Skip to content

Commit

Permalink
feat: support 'virtual' dependencies (#201)
Browse files Browse the repository at this point in the history
Fixes #213

---------

Co-authored-by: Alex Eagle <[email protected]>
  • Loading branch information
mattem and alexeagle authored Nov 14, 2023
1 parent 9252988 commit cb5fef7
Show file tree
Hide file tree
Showing 22 changed files with 593 additions and 31 deletions.
4 changes: 4 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ test --test_output=errors
# Define value used by tests
build --define=SOME_VAR=SOME_VALUE

# Use local rules_python
# Enable with --config=dev
common:dev --override_repository=rules_python=~/workspace/rules_python

# Load any settings specific to the current user.
# .bazelrc.user should appear in .gitignore so that settings are not shared with team members
# This needs to be last statement in this
Expand Down
8 changes: 7 additions & 1 deletion WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ rules_py_dependencies()
# Load the Python toolchain for rules_docker
register_toolchains("//:container_py_toolchain")

load("@rules_python//python:repositories.bzl", "python_register_toolchains")
load("@rules_python//python:repositories.bzl", "py_repositories", "python_register_toolchains")

python_register_toolchains(
name = "python_toolchain",
python_version = "3.9",
)

py_repositories()

############################################
# Aspect gcc toolchain
load("@aspect_gcc_toolchain//toolchain:repositories.bzl", "gcc_toolchain_dependencies")
Expand All @@ -47,6 +49,10 @@ load("@pypi//:requirements.bzl", "install_deps")

install_deps()

load("@django//:requirements.bzl", install_django_deps = "install_deps")

install_django_deps()

################################
# For running our own unit tests
load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace")
Expand Down
111 changes: 99 additions & 12 deletions docs/rules.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 22 additions & 1 deletion internal_deps.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Users should *not* need to install these. If users see a load()
statement from these, that's a bug in our distribution.
"""

load("@bazel_tools//tools/build_defs/repo:http.bzl", _http_archive = "http_archive")
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_file", _http_archive = "http_archive")
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")

def http_archive(name, **kwargs):
Expand Down Expand Up @@ -90,3 +90,24 @@ def rules_py_internal_deps():
strip_prefix = "rules_python-0.18.0/gazelle",
url = "https://github.com/bazelbuild/rules_python/releases/download/0.18.0/rules_python-0.18.0.tar.gz",
)

http_file(
name = "django_4_2_4",
urls = ["https://files.pythonhosted.org/packages/7f/9e/fc6bab255ae10bc57fa2f65646eace3d5405fbb7f5678b90140052d1db0f/Django-4.2.4-py3-none-any.whl"],
sha256 = "860ae6a138a238fc4f22c99b52f3ead982bb4b1aad8c0122bcd8c8a3a02e409d",
downloaded_file_path = "Django-4.2.4-py3-none-any.whl",
)

http_file(
name = "django_4_1_10",
urls = ["https://files.pythonhosted.org/packages/34/25/8a218de57fc9853297a1a8e4927688eff8107d5bc6dcf6c964c59801f036/Django-4.1.10-py3-none-any.whl"],
sha256 = "26d0260c2fb8121009e62ffc548b2398dea2522b6454208a852fb0ef264c206c",
downloaded_file_path = "Django-4.1.10-py3-none-any.whl",
)

http_file(
name = "sqlparse_0_4_0",
urls = ["https://files.pythonhosted.org/packages/10/96/36c136013c4a6ecb8c6aa3eed66e6dcea838f85fd80e1446499f1dabfac7/sqlparse-0.4.0-py3-none-any.whl"],
sha256 = "0523026398aea9c8b5f7a4a6d5c0829c285b4fbd960c17b5967a369342e21e01",
downloaded_file_path = "sqlparse-0.4.0-py3-none-any.whl",
)
9 changes: 8 additions & 1 deletion internal_python_deps.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@ py_wheel(
)
"""

# buildifier: disable=function-docstring
def rules_py_internal_pypi_deps(interpreter):
# Here we can see an example of annotations being applied to an arbitrary
# package. For details on `package_annotation` and it's uses, see the
# docs at @rules_python//docs:pip.md`.

PACKAGES = ["django", "colorama", "django"]
PACKAGES = ["django", "colorama"]
ANNOTATIONS = {
pkg: package_annotation(additive_build_content = PY_WHEEL_RULE_CONTENT)
for pkg in PACKAGES
Expand All @@ -33,3 +34,9 @@ def rules_py_internal_pypi_deps(interpreter):
python_interpreter_target = interpreter,
requirements_lock = "//:requirements.txt",
)

pip_parse(
name = "django",
python_interpreter_target = interpreter,
requirements_lock = "//py/tests/virtual/django:requirements.txt",
)
Loading

0 comments on commit cb5fef7

Please sign in to comment.