diff options
Diffstat (limited to 'examples/bzlmod/other_module')
-rw-r--r-- | examples/bzlmod/other_module/BUILD.bazel | 9 | ||||
-rw-r--r-- | examples/bzlmod/other_module/MODULE.bazel | 32 | ||||
-rw-r--r-- | examples/bzlmod/other_module/other_module/pkg/BUILD.bazel | 16 | ||||
-rw-r--r-- | examples/bzlmod/other_module/other_module/pkg/bin.py | 6 | ||||
-rw-r--r-- | examples/bzlmod/other_module/requirements.in | 1 | ||||
-rw-r--r-- | examples/bzlmod/other_module/requirements_lock_3_11.txt | 10 |
6 files changed, 66 insertions, 8 deletions
diff --git a/examples/bzlmod/other_module/BUILD.bazel b/examples/bzlmod/other_module/BUILD.bazel new file mode 100644 index 0000000..a93b92a --- /dev/null +++ b/examples/bzlmod/other_module/BUILD.bazel @@ -0,0 +1,9 @@ +load("@python_versions//3.11:defs.bzl", compile_pip_requirements_311 = "compile_pip_requirements") + +# NOTE: To update the requirements, you need to uncomment the rules_python +# override in the MODULE.bazel. +compile_pip_requirements_311( + name = "requirements", + src = "requirements.in", + requirements_txt = "requirements_lock_3_11.txt", +) diff --git a/examples/bzlmod/other_module/MODULE.bazel b/examples/bzlmod/other_module/MODULE.bazel index cc23a51..959501a 100644 --- a/examples/bzlmod/other_module/MODULE.bazel +++ b/examples/bzlmod/other_module/MODULE.bazel @@ -6,10 +6,20 @@ module( # that the parent module uses. bazel_dep(name = "rules_python", version = "") -# It is not best practice to use a python.toolchian in -# a submodule. This code only exists to test that -# we support doing this. This code is only for rules_python -# testing purposes. +# The story behind this commented out override: +# This override is necessary to generate/update the requirements file +# for this module. This is because running it via the outer +# module doesn't work -- the `requirements.update` target can't find +# the correct file to update. +# Running in the submodule itself works, but submodules using overrides +# is considered an error until Bazel 6.3, which prevents the outer module +# from depending on this module. +# So until 6.3 and higher is the minimum, we leave this commented out. +# local_path_override( +# module_name = "rules_python", +# path = "../../..", +# ) + PYTHON_NAME_39 = "python_3_9" PYTHON_NAME_311 = "python_3_11" @@ -29,6 +39,20 @@ python.toolchain( # created by the above python.toolchain calls. use_repo( python, + "python_versions", PYTHON_NAME_39, PYTHON_NAME_311, ) + +pip = use_extension("@rules_python//python/extensions:pip.bzl", "pip") +pip.parse( + hub_name = "other_module_pip", + # NOTE: This version must be different than the root module's + # default python version. + # This is testing that a sub-module can use pip.parse() and only specify + # Python versions that DON'T include whatever the root-module's default + # Python version is. + python_version = "3.11", + requirements_lock = ":requirements_lock_3_11.txt", +) +use_repo(pip, "other_module_pip") diff --git a/examples/bzlmod/other_module/other_module/pkg/BUILD.bazel b/examples/bzlmod/other_module/other_module/pkg/BUILD.bazel index 6e37df8..021c969 100644 --- a/examples/bzlmod/other_module/other_module/pkg/BUILD.bazel +++ b/examples/bzlmod/other_module/other_module/pkg/BUILD.bazel @@ -1,4 +1,7 @@ -load("@python_3_11//:defs.bzl", py_binary_311 = "py_binary") +load( + "@python_3_11//:defs.bzl", + py_binary_311 = "py_binary", +) load("@rules_python//python:defs.bzl", "py_library") py_library( @@ -13,11 +16,16 @@ py_library( # used only when you need to support multiple versions of Python # in the same project. py_binary_311( - name = "lib_311", - srcs = ["lib.py"], + name = "bin", + srcs = ["bin.py"], data = ["data/data.txt"], + main = "bin.py", visibility = ["//visibility:public"], - deps = ["@rules_python//python/runfiles"], + deps = [ + ":lib", + "@other_module_pip//absl_py", + "@rules_python//python/runfiles", + ], ) exports_files(["data/data.txt"]) diff --git a/examples/bzlmod/other_module/other_module/pkg/bin.py b/examples/bzlmod/other_module/other_module/pkg/bin.py new file mode 100644 index 0000000..3e28ca2 --- /dev/null +++ b/examples/bzlmod/other_module/other_module/pkg/bin.py @@ -0,0 +1,6 @@ +import sys + +import absl + +print("Python version:", sys.version) +print("Module 'absl':", absl) diff --git a/examples/bzlmod/other_module/requirements.in b/examples/bzlmod/other_module/requirements.in new file mode 100644 index 0000000..b998a06 --- /dev/null +++ b/examples/bzlmod/other_module/requirements.in @@ -0,0 +1 @@ +absl-py diff --git a/examples/bzlmod/other_module/requirements_lock_3_11.txt b/examples/bzlmod/other_module/requirements_lock_3_11.txt new file mode 100644 index 0000000..7e350f2 --- /dev/null +++ b/examples/bzlmod/other_module/requirements_lock_3_11.txt @@ -0,0 +1,10 @@ +# +# This file is autogenerated by pip-compile with Python 3.11 +# by the following command: +# +# bazel run //other_module/pkg:requirements.update +# +absl-py==1.4.0 \ + --hash=sha256:0d3fe606adfa4f7db64792dd4c7aee4ee0c38ab75dfd353b7a83ed3e957fcb47 \ + --hash=sha256:d2c244d01048ba476e7c080bd2c6df5e141d211de80223460d5b3b8a2a58433d + # via -r other_module/pkg/requirements.in |