Skip to content

Commit 2ab8e3c

Browse files
committed
chore: also enable pipstar on WORKSPACE
1 parent 1194739 commit 2ab8e3c

File tree

9 files changed

+34
-34
lines changed

9 files changed

+34
-34
lines changed

CHANGELOG.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,10 @@ END_UNRELEASED_TEMPLATE
6969
* (bootstrap) For {obj}`--bootstrap_impl=system_python`, the sys.path order has
7070
changed from `[app paths, stdlib, runtime site-packages]` to `[stdlib, app
7171
paths, runtime site-packages]`.
72-
* (pypi) `pipstar` flag has been flipped to be enabled by default for bzlmod
73-
([#2949](https://github.com/bazel-contrib/rules_python/issues/2949)).
72+
* (pypi) `pipstar` flag has been flipped to be enabled by default, to turn it
73+
off use `RULES_PYTHON_ENABLE_PIPSTAR=0` environment variable. If you do, please
74+
add a comment to
75+
[#2949](https://github.com/bazel-contrib/rules_python/issues/2949).
7476

7577
{#v0-0-0-fixed}
7678
### Fixed

examples/pip_parse_vendored/requirements.bzl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ all_data_requirements = [
3232
"@my_project_pip_deps_vendored_urllib3//:data",
3333
]
3434

35+
packages = sorted(all_whl_requirements_by_package)
36+
3537
_packages = [
3638
("my_project_pip_deps_vendored_certifi", "certifi==2023.7.22 --hash=sha256:539cc1d13202e33ca466e88b2807e29f4c13049d6d87031a3c110744495cb082 --hash=sha256:92d6037539857d8206b8f6ae472e8b77db8058fec5937a1ef3f54304089edbb9"),
3739
("my_project_pip_deps_vendored_charset_normalizer", "charset-normalizer==2.1.1 --hash=sha256:5a3d016c7c547f69d6f81fb0db9449ce888b418b5b9952cc5e6e66843e9dd845 --hash=sha256:83e9a75d1911279afd89352c68b45348559d1fc0506b054b346651b5e7fee29f"),
@@ -112,5 +114,6 @@ def install_deps(**whl_library_kwargs):
112114
group_name = group_name,
113115
group_deps = group_deps,
114116
annotation = _get_annotation(requirement),
117+
packages = packages,
115118
**whl_config
116119
)

python/private/pypi/config.bzl.tmpl.bzlmod

Lines changed: 0 additions & 9 deletions
This file was deleted.

python/private/pypi/generate_whl_library_build_bazel.bzl

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ def generate_whl_library_build_bazel(
7272
"requires",
7373
"metadata_name",
7474
"metadata_version",
75+
"packages",
7576
"include",
7677
]
7778
else:
@@ -83,16 +84,20 @@ def generate_whl_library_build_bazel(
8384
"default_python_version",
8485
]
8586
dep_template = kwargs.get("dep_template")
86-
loads.append(
87-
"""load("{}", "{}")""".format(
88-
dep_template.format(
89-
name = "",
90-
target = "config.bzl",
87+
packages = kwargs.pop("packages", [])
88+
if packages:
89+
kwargs["include"] = render.list(packages)
90+
else:
91+
loads.append(
92+
"""load("{}", "{}")""".format(
93+
dep_template.format(
94+
name = "",
95+
target = "requirements.bzl",
96+
),
97+
"packages",
9198
),
92-
"whl_map",
93-
),
94-
)
95-
kwargs["include"] = "whl_map"
99+
)
100+
kwargs["include"] = "packages"
96101

97102
for arg in unsupported_args:
98103
if kwargs.get(arg):

python/private/pypi/hub_repository.bzl

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,6 @@ def _impl(rctx):
4646
macro_tmpl = "@@{name}//{{}}:{{}}".format(name = rctx.attr.name)
4747

4848
rctx.file("BUILD.bazel", _BUILD_FILE_CONTENTS)
49-
rctx.template(
50-
"config.bzl",
51-
rctx.attr._config_template,
52-
substitutions = {
53-
"%%WHL_MAP%%": render.dict(rctx.attr.whl_map, value_repr = lambda x: "None"),
54-
},
55-
)
5649
rctx.template("requirements.bzl", rctx.attr._requirements_bzl_template, substitutions = {
5750
"%%ALL_DATA_REQUIREMENTS%%": render.list([
5851
macro_tmpl.format(p, "data")
@@ -99,9 +92,6 @@ The wheel map where values are json.encoded strings of the whl_map constructed
9992
in the pip.parse tag class.
10093
""",
10194
),
102-
"_config_template": attr.label(
103-
default = ":config.bzl.tmpl.bzlmod",
104-
),
10595
"_requirements_bzl_template": attr.label(
10696
default = ":requirements.bzl.tmpl.bzlmod",
10797
),

python/private/pypi/requirements.bzl.tmpl.bzlmod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ all_whl_requirements = all_whl_requirements_by_package.values()
1313

1414
all_data_requirements = %%ALL_DATA_REQUIREMENTS%%
1515

16+
packages = sorted(all_whl_requirements_by_package)
17+
1618
def requirement(name):
1719
return "%%MACRO_TMPL%%".format(pip_utils.normalize_name(name), "pkg")
1820

python/private/pypi/requirements.bzl.tmpl.workspace

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ all_whl_requirements = all_whl_requirements_by_package.values()
1313

1414
all_data_requirements = %%ALL_DATA_REQUIREMENTS%%
1515

16+
packages = sorted(all_whl_requirements_by_package)
17+
1618
_packages = %%PACKAGES%%
1719
_config = %%CONFIG%%
1820
_annotations = %%ANNOTATIONS%%
@@ -68,5 +70,6 @@ def install_deps(**whl_library_kwargs):
6870
group_name = group_name,
6971
group_deps = group_deps,
7072
annotation = _get_annotation(requirement),
73+
packages = packages,
7174
**whl_config
7275
)

python/private/pypi/whl_library.bzl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,7 @@ def _whl_library_impl(rctx):
423423
name = whl_path.basename,
424424
sdist_filename = sdist_filename,
425425
dep_template = rctx.attr.dep_template or "@{}{{name}}//:{{target}}".format(rctx.attr.repo_prefix),
426+
packages = rctx.attr.packages,
426427
entry_points = entry_points,
427428
metadata_name = metadata.name,
428429
metadata_version = metadata.version,
@@ -592,6 +593,9 @@ For example if your whl depends on `numpy` and your Python package repo is named
592593
"group_name": attr.string(
593594
doc = "Name of the group, if any.",
594595
),
596+
"packages": attr.string_list(
597+
doc = "The list of packages to include in the transitive dependencies. This may be used in workspace where one may vendor the requirements.bzl file.",
598+
),
595599
"repo": attr.string(
596600
doc = "Pointer to parent repo name. Used to make these rules rerun if the parent repo changes.",
597601
),

tests/pypi/generate_whl_library_build_bazel/generate_whl_library_build_bazel_tests.bzl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ _tests.append(_test_all_legacy)
8585

8686
def _test_all(env):
8787
want = """\
88-
load("@pypi//:config.bzl", "whl_map")
88+
load("@pypi//:requirements.bzl", "packages")
8989
load("@rules_python//python/private/pypi:whl_library_targets.bzl", "whl_library_targets_from_requires")
9090
9191
package(default_visibility = ["//visibility:public"])
@@ -112,7 +112,7 @@ whl_library_targets_from_requires(
112112
"qux",
113113
],
114114
group_name = "qux",
115-
include = whl_map,
115+
include = packages,
116116
name = "foo.whl",
117117
requires_dist = [
118118
"foo",
@@ -149,7 +149,7 @@ _tests.append(_test_all)
149149

150150
def _test_all_with_loads(env):
151151
want = """\
152-
load("@pypi//:config.bzl", "whl_map")
152+
load("@pypi//:requirements.bzl", "packages")
153153
load("@rules_python//python/private/pypi:whl_library_targets.bzl", "whl_library_targets_from_requires")
154154
155155
package(default_visibility = ["//visibility:public"])
@@ -176,7 +176,7 @@ whl_library_targets_from_requires(
176176
"qux",
177177
],
178178
group_name = "qux",
179-
include = whl_map,
179+
include = packages,
180180
name = "foo.whl",
181181
requires_dist = [
182182
"foo",

0 commit comments

Comments
 (0)