Skip to content

Commit be0144c

Browse files
committed
make platforms mandatory internally and configure them in the root MODULE
1 parent 134fa8f commit be0144c

File tree

7 files changed

+73
-67
lines changed

7 files changed

+73
-67
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ END_UNRELEASED_TEMPLATE
104104
Set the `RULES_PYTHON_ENABLE_PIPSTAR=1` environment variable to enable it.
105105
* (utils) Add a way to run a REPL for any `rules_python` target that returns
106106
a `PyInfo` provider.
107+
* (pypi) Added early developer preview `pip.default` tag class in order to customize what
108+
platforms are enabled. Only `rules_python` and root modules can use this feature.
107109

108110
{#v0-0-0-removed}
109111
### Removed

MODULE.bazel

Lines changed: 41 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -65,40 +65,47 @@ _DEFAULT_OSX_PLATFORM_VERSION = "14.0"
6565

6666
_DEFAULT_WINDOWS_PLATFORM_VERSION = "0"
6767

68-
pip.default(
69-
arch_name = "x86_64",
70-
constraint_values = [
71-
"@platforms//os:linux",
72-
"@platforms//cpu:x86_64",
73-
],
74-
env_platform_version = _DEFAULT_LINUX_PLATFORM_VERSION,
75-
os_name = "linux",
76-
platform = "linux_x86_64",
77-
)
78-
pip.default(
79-
arch_name = "x86_64",
80-
constraint_values = [
81-
"@platforms//os:osx",
82-
"@platforms//cpu:x86_64",
83-
],
84-
# We choose the oldest non-EOL version at the time when we release `rules_python`.
85-
# See https://endoflife.date/macos
86-
env_platform_version = _DEFAULT_OSX_PLATFORM_VERSION,
87-
os_name = "osx",
88-
platform = "osx_x86_64",
89-
)
90-
pip.default(
91-
arch_name = "aarch64",
92-
constraint_values = [
93-
"@platforms//os:osx",
94-
"@platforms//cpu:aarch64",
95-
],
96-
# We choose the oldest non-EOL version at the time when we release `rules_python`.
97-
# See https://endoflife.date/macos
98-
env_platform_version = _DEFAULT_OSX_PLATFORM_VERSION,
99-
os_name = "osx",
100-
platform = "osx_aarch64",
101-
)
68+
[
69+
pip.default(
70+
arch_name = cpu,
71+
constraint_values = [
72+
"@platforms//os:linux",
73+
"@platforms//cpu:{}".format(cpu),
74+
],
75+
env_platform_version = _DEFAULT_LINUX_PLATFORM_VERSION,
76+
os_name = "linux",
77+
platform = "linux_{}".format(cpu),
78+
)
79+
# TODO @aignas 2025-05-19: only leave tier 0-1 cpus when stabilizing the
80+
# `pip.default` extension
81+
for cpu in [
82+
"aarch64",
83+
"arm",
84+
"ppc",
85+
"s390x",
86+
"x86_64",
87+
]
88+
]
89+
90+
[
91+
pip.default(
92+
arch_name = cpu,
93+
constraint_values = [
94+
"@platforms//os:osx",
95+
"@platforms//cpu:{}".format(cpu),
96+
],
97+
# We choose the oldest non-EOL version at the time when we release `rules_python`.
98+
# See https://endoflife.date/macos
99+
env_platform_version = _DEFAULT_OSX_PLATFORM_VERSION,
100+
os_name = "osx",
101+
platform = "osx_{}".format(cpu),
102+
)
103+
for cpu in [
104+
"aarch64",
105+
"x86_64",
106+
]
107+
]
108+
102109
pip.default(
103110
arch_name = "x86_64",
104111
constraint_values = [

python/private/pypi/extension.bzl

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -307,12 +307,6 @@ def _create_whl_repos(
307307
},
308308
extra_aliases = extra_aliases,
309309
whl_libraries = whl_libraries,
310-
target_platforms = {
311-
plat: None
312-
for reqs in requirements_by_platform.values()
313-
for req in reqs
314-
for plat in req.target_platforms
315-
},
316310
)
317311

318312
def _whl_repos(*, requirement, whl_library_args, download_only, netrc, auth_patterns, multiple_requirements_for_whl = False, python_version, enable_pipstar = False):
@@ -545,7 +539,6 @@ You cannot use both the additive_build_content and additive_build_content_file a
545539
hub_group_map = {}
546540
exposed_packages = {}
547541
extra_aliases = {}
548-
target_platforms = {}
549542
whl_libraries = {}
550543

551544
for mod in module_ctx.modules:
@@ -629,7 +622,6 @@ You cannot use both the additive_build_content and additive_build_content_file a
629622
for whl_name, aliases in out.extra_aliases.items():
630623
extra_aliases[hub_name].setdefault(whl_name, {}).update(aliases)
631624
exposed_packages.setdefault(hub_name, {}).update(out.exposed_packages)
632-
target_platforms.setdefault(hub_name, {}).update(out.target_platforms)
633625
whl_libraries.update(out.whl_libraries)
634626

635627
# TODO @aignas 2024-04-05: how do we support different requirement
@@ -667,10 +659,6 @@ You cannot use both the additive_build_content and additive_build_content_file a
667659
}
668660
for hub_name, extra_whl_aliases in extra_aliases.items()
669661
},
670-
target_platforms = {
671-
hub_name: sorted(p)
672-
for hub_name, p in target_platforms.items()
673-
},
674662
whl_libraries = {
675663
k: dict(sorted(args.items()))
676664
for k, args in sorted(whl_libraries.items())
@@ -762,14 +750,13 @@ def _pip_impl(module_ctx):
762750
},
763751
packages = mods.exposed_packages.get(hub_name, []),
764752
groups = mods.hub_group_map.get(hub_name),
765-
target_platforms = mods.target_platforms.get(hub_name, []),
766753
)
767754

768755
if bazel_features.external_deps.extension_metadata_has_reproducible:
769756
# NOTE @aignas 2025-04-15: this is set to be reproducible, because the
770757
# results after calling the PyPI index should be reproducible on each
771758
# machine.
772-
return module_ctx.extension_metadata(reproducible = False)
759+
return module_ctx.extension_metadata(reproducible = True)
773760
else:
774761
return None
775762

python/private/pypi/hub_repository.bzl

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,6 @@ The list of packages that will be exposed via all_*requirements macros. Defaults
8787
mandatory = True,
8888
doc = "The apparent name of the repo. This is needed because in bzlmod, the name attribute becomes the canonical name.",
8989
),
90-
"target_platforms": attr.string_list(
91-
mandatory = True,
92-
doc = "All of the target platforms for the hub repo",
93-
),
9490
"whl_map": attr.string_dict(
9591
mandatory = True,
9692
doc = """\

python/private/pypi/pip_repository.bzl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,16 @@ def _pip_repository_impl(rctx):
8080
requirements_osx = rctx.attr.requirements_darwin,
8181
requirements_windows = rctx.attr.requirements_windows,
8282
extra_pip_args = rctx.attr.extra_pip_args,
83+
platforms = [
84+
"linux_aarch64",
85+
"linux_arm",
86+
"linux_ppc",
87+
"linux_s390x",
88+
"linux_x86_64",
89+
"osx_aarch64",
90+
"osx_x86_64",
91+
"windows_x86_64",
92+
],
8393
),
8494
extra_pip_args = rctx.attr.extra_pip_args,
8595
evaluate_markers = lambda rctx, requirements: evaluate_markers_py(

python/private/pypi/requirements_files_by_platform.bzl

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,6 @@
1616

1717
load(":whl_target_platforms.bzl", "whl_target_platforms")
1818

19-
# TODO @aignas 2024-05-13: consider using the same platform tags as are used in
20-
# the //python:versions.bzl
21-
DEFAULT_PLATFORMS = [
22-
"linux_aarch64",
23-
"linux_arm",
24-
"linux_ppc",
25-
"linux_s390x",
26-
"linux_x86_64",
27-
"osx_aarch64",
28-
"osx_x86_64",
29-
"windows_x86_64",
30-
]
31-
3219
def _default_platforms_from(*, filter, python_version, choose_from):
3320
if not filter:
3421
fail("Must specific a filter string, got: {}".format(filter))
@@ -149,7 +136,7 @@ def requirements_files_by_platform(
149136
_default_platforms = lambda f: _default_platforms_from(
150137
filter = f,
151138
python_version = python_version,
152-
choose_from = platforms or DEFAULT_PLATFORMS,
139+
choose_from = platforms,
153140
)
154141

155142
platforms_from_args = _platforms_from_args(extra_pip_args)

tests/pypi/requirements_files_by_platform/requirements_files_by_platform_tests.bzl

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,27 @@
1515
""
1616

1717
load("@rules_testing//lib:test_suite.bzl", "test_suite")
18-
load("//python/private/pypi:requirements_files_by_platform.bzl", "requirements_files_by_platform") # buildifier: disable=bzl-visibility
18+
load("//python/private/pypi:requirements_files_by_platform.bzl", _sut = "requirements_files_by_platform") # buildifier: disable=bzl-visibility
1919

2020
_tests = []
2121

22+
requirements_files_by_platform = lambda **kwargs: _sut(
23+
platforms = kwargs.pop(
24+
"platforms",
25+
[
26+
"linux_aarch64",
27+
"linux_arm",
28+
"linux_ppc",
29+
"linux_s390x",
30+
"linux_x86_64",
31+
"osx_aarch64",
32+
"osx_x86_64",
33+
"windows_x86_64",
34+
],
35+
),
36+
**kwargs
37+
)
38+
2239
def _test_fail_no_requirements(env):
2340
errors = []
2441
requirements_files_by_platform(

0 commit comments

Comments
 (0)