diff --git a/docs/pip_repository.md b/docs/pip_repository.md index 29cb3d9c32..7d539c9c44 100644 --- a/docs/pip_repository.md +++ b/docs/pip_repository.md @@ -85,8 +85,9 @@ py_binary( ## pip_repository_bzlmod
-pip_repository_bzlmod(name, incompatible_generate_aliases, repo_mapping, requirements_darwin, - requirements_linux, requirements_lock, requirements_windows) +pip_repository_bzlmod(name, incompatible_generate_aliases, repo_mapping, repo_name, + requirements_darwin, requirements_linux, requirements_lock, + requirements_windows)A rule for bzlmod pip_repository creation. Intended for private use only. @@ -99,6 +100,7 @@ A rule for bzlmod pip_repository creation. Intended for private use only. | name | A unique name for this repository. | Name | required | | | incompatible_generate_aliases | Allow generating aliases in '@pip//:<pkg>' -> '@pip_<pkg>//:pkg'. This replaces the aliases generated by the
bzlmod
tooling. | Boolean | optional | False
|
| repo_mapping | A dictionary from local repository name to global repository name. This allows controls over workspace dependency resolution for dependencies of this repository.<p>For example, an entry "@foo": "@bar"
declares that, for any time this repository depends on @foo
(such as a dependency on @foo//some:target
, it should actually resolve that dependency within globally-declared @bar
(@bar//some:target
). | Dictionary: String -> String | required | |
+| repo_name | The apparent name of the repo. This is needed because in bzlmod, the name attribute becomes the canonical name | String | required | |
| requirements_darwin | Override the requirements_lock attribute when the host platform is Mac OS | Label | optional | None
|
| requirements_linux | Override the requirements_lock attribute when the host platform is Linux | Label | optional | None
|
| requirements_lock | A fully resolved 'requirements.txt' pip requirement file containing the transitive set of your dependencies. If this file is passed instead of 'requirements' no resolve will take place and pip_repository will create individual repositories for each of your dependencies so that wheels are fetched/built only for the targets specified by 'build/run/test'. | Label | optional | None
|
diff --git a/examples/bzlmod/BUILD.bazel b/examples/bzlmod/BUILD.bazel
index 7ecc035853..3183608897 100644
--- a/examples/bzlmod/BUILD.bazel
+++ b/examples/bzlmod/BUILD.bazel
@@ -1,4 +1,5 @@
-load("@pip//:requirements.bzl", "requirement")
+load("@bazel_skylib//rules:build_test.bzl", "build_test")
+load("@pip//:requirements.bzl", "all_requirements", "all_whl_requirements", "requirement")
load("@python3_9//:defs.bzl", py_test_with_transition = "py_test")
load("@rules_python//python:defs.bzl", "py_binary", "py_library", "py_test")
load("@rules_python//python:pip.bzl", "compile_pip_requirements")
@@ -43,3 +44,13 @@ py_test_with_transition(
main = "test.py",
deps = [":lib"],
)
+
+build_test(
+ name = "all_wheels",
+ targets = all_whl_requirements,
+)
+
+build_test(
+ name = "all_requirements",
+ targets = all_requirements,
+)
diff --git a/examples/bzlmod/MODULE.bazel b/examples/bzlmod/MODULE.bazel
index 61d7967d5e..d2d7d63871 100644
--- a/examples/bzlmod/MODULE.bazel
+++ b/examples/bzlmod/MODULE.bazel
@@ -4,6 +4,7 @@ module(
compatibility_level = 1,
)
+bazel_dep(name = "bazel_skylib", version = "1.4.1")
bazel_dep(name = "rules_python", version = "0.0.0")
local_path_override(
module_name = "rules_python",
@@ -26,6 +27,8 @@ register_toolchains(
pip = use_extension("@rules_python//python/extensions:pip.bzl", "pip")
pip.parse(
name = "pip",
+ # Intentionally set it false because the "true" case is already covered by examples/bzlmod_build_file_generation
+ incompatible_generate_aliases = False,
requirements_lock = "//:requirements_lock.txt",
requirements_windows = "//:requirements_windows.txt",
)
diff --git a/python/extensions/pip.bzl b/python/extensions/pip.bzl
index 2ec2bbf404..ce5eea30d4 100644
--- a/python/extensions/pip.bzl
+++ b/python/extensions/pip.bzl
@@ -34,6 +34,7 @@ def _pip_impl(module_ctx):
# this does not create the install_deps() macro.
pip_repository_bzlmod(
name = attr.name,
+ repo_name = attr.name,
requirements_lock = attr.requirements_lock,
incompatible_generate_aliases = attr.incompatible_generate_aliases,
)
diff --git a/python/pip_install/pip_repository.bzl b/python/pip_install/pip_repository.bzl
index 5462f1b14d..406e12113d 100644
--- a/python/pip_install/pip_repository.bzl
+++ b/python/pip_install/pip_repository.bzl
@@ -358,7 +358,7 @@ def _pip_repository_bzlmod_impl(rctx):
bzl_packages = sorted([name for name, _ in packages])
- repo_name = rctx.attr.name.split("~")[-1]
+ repo_name = rctx.attr.repo_name
build_contents = _BUILD_FILE_CONTENTS
@@ -379,11 +379,11 @@ def _pip_repository_bzlmod_impl(rctx):
rctx.file("BUILD.bazel", build_contents)
rctx.template("requirements.bzl", rctx.attr._template, substitutions = {
"%%ALL_REQUIREMENTS%%": _format_repr_list([
- "@{}//{}".format(repo_name, p) if rctx.attr.incompatible_generate_aliases else "@{}_{}//:pkg".format(rctx.attr.name, p)
+ macro_tmpl.format(p, p) if rctx.attr.incompatible_generate_aliases else macro_tmpl.format(p, "pkg")
for p in bzl_packages
]),
"%%ALL_WHL_REQUIREMENTS%%": _format_repr_list([
- "@{}//{}:whl".format(repo_name, p) if rctx.attr.incompatible_generate_aliases else "@{}_{}//:whl".format(rctx.attr.name, p)
+ macro_tmpl.format(p, "whl")
for p in bzl_packages
]),
"%%MACRO_TMPL%%": macro_tmpl,
@@ -395,6 +395,10 @@ pip_repository_bzlmod_attrs = {
default = False,
doc = "Allow generating aliases in '@pip//: