Skip to content

Commit 8c916f3

Browse files
committed
fix(pypi): pull fewer wheels with experimental_index_url
Before this we would pull all of the wheels that the user target configuration would be compatible with and that meant that it was not customizable. This also meant that there were a lot of footguns in the configuration where the select statements were not really foolproof. With this PR we select only those sources that need to be for the declared configurations. Freethreaded support is done by defining extra freethreaded platforms using the new builder API (bazel-contrib#3063). This is also changing the default platforms to be only the fully supported platforms. This makes the testing easier and avoids us running into compatibility issues during the roll out. Work towards bazel-contrib#2747 Fixes bazel-contrib#2759 Fixes bazel-contrib#2849
1 parent f2e68cf commit 8c916f3

File tree

12 files changed

+426
-672
lines changed

12 files changed

+426
-672
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ END_UNRELEASED_TEMPLATE
6969
* (toolchain) Python 3.13 now references 3.13.5
7070
* (gazelle) Switched back to smacker/go-tree-sitter, fixing
7171
[#2630](https://github.com/bazel-contrib/rules_python/issues/2630)
72+
* (pypi) From now on the list of default platforms only includes `linux_x86_64`, `linux_aarch64`,
73+
`osx_x86_64`, `osx_aarch64` and `windows_x86_64`. If you are on other platforms, you need to
74+
use the `pip.default` to configure it yourself. If you are interested in graduating the
75+
platform, consider helping set us up CI for them and update the documentation.
7276
* (ci) We are now testing on Ubuntu 22.04 for RBE and non-RBE configurations.
7377
* (core) #!/usr/bin/env bash is now used as a shebang in the stage1 bootstrap template.
7478

@@ -88,6 +92,10 @@ END_UNRELEASED_TEMPLATE
8892
([#3043](https://github.com/bazel-contrib/rules_python/issues/3043)).
8993
* (pypi) The pipstar `defaults` configuration now supports any custom platform
9094
name.
95+
* (pypi) The selection of the whls has been changed and should no longer result
96+
in ambiguous select matches ({gh-issue}`2759`) and should be much more efficient
97+
when running `bazel query` due to fewer repositories being included
98+
({gh-issue}`2849`).
9199
* Multi-line python imports (e.g. with escaped newlines) are now correctly processed by Gazelle.
92100
* (toolchains) `local_runtime_repo` works with multiarch Debian with Python 3.8
93101
([#3099](https://github.com/bazel-contrib/rules_python/issues/3099)).

MODULE.bazel

Lines changed: 49 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -74,16 +74,18 @@ pip = use_extension("//python/extensions:pip.bzl", "pip")
7474
env = {"platform_version": "0"},
7575
os_name = "linux",
7676
platform = "linux_{}".format(cpu),
77+
whl_abi_tags = [
78+
"abi3",
79+
"cp{major}{minor}",
80+
],
81+
whl_platform_tags = [
82+
"linux_{}".format(cpu),
83+
"manylinux_*_{}".format(cpu),
84+
],
7785
)
7886
for cpu in [
7987
"x86_64",
8088
"aarch64",
81-
# TODO @aignas 2025-05-19: only leave tier 0-1 cpus when stabilizing the
82-
# `pip.default` extension. i.e. drop the below values - users will have to
83-
# define themselves if they need them.
84-
"arm",
85-
"ppc",
86-
"s390x",
8789
]
8890
]
8991

@@ -99,26 +101,53 @@ pip = use_extension("//python/extensions:pip.bzl", "pip")
99101
env = {"platform_version": "14.0"},
100102
os_name = "osx",
101103
platform = "osx_{}".format(cpu),
104+
whl_abi_tags = [
105+
"abi3",
106+
"cp{major}{minor}",
107+
],
108+
whl_platform_tags = [
109+
"macosx_*_{}".format(suffix)
110+
for suffix in platform_tag_cpus
111+
],
102112
)
103-
for cpu in [
104-
"aarch64",
105-
"x86_64",
106-
]
113+
for cpu, platform_tag_cpus in {
114+
"aarch64": [
115+
"universal2",
116+
"arm64",
117+
],
118+
"x86_64": [
119+
"universal2",
120+
"x86_64",
121+
],
122+
}.items()
123+
]
124+
125+
[
126+
pip.default(
127+
arch_name = cpu,
128+
config_settings = [
129+
"@platforms//cpu:{}".format(cpu),
130+
"@platforms//os:windows",
131+
],
132+
env = {"platform_version": "0"},
133+
os_name = "windows",
134+
platform = "windows_{}".format(cpu),
135+
whl_abi_tags = [
136+
"abi3",
137+
"cp{major}{minor}",
138+
],
139+
whl_platform_tags = whl_platform_tags,
140+
)
141+
for cpu, whl_platform_tags in {
142+
"x86_64": ["win_amd64"],
143+
}.items()
107144
]
108145

109-
pip.default(
110-
arch_name = "x86_64",
111-
config_settings = [
112-
"@platforms//cpu:x86_64",
113-
"@platforms//os:windows",
114-
],
115-
env = {"platform_version": "0"},
116-
os_name = "windows",
117-
platform = "windows_x86_64",
118-
)
119146
pip.parse(
120147
# NOTE @aignas 2024-10-26: We have an integration test that depends on us
121148
# being able to build sdists for this hub, so explicitly set this to False.
149+
#
150+
# how do we test sdists? Maybe just worth adding a single sdist somewhere?
122151
download_only = False,
123152
experimental_index_url = "https://pypi.org/simple",
124153
hub_name = "rules_python_publish_deps",

examples/bzlmod/MODULE.bazel

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,23 @@ pip.whl_mods(
158158
)
159159
use_repo(pip, "whl_mods_hub")
160160

161+
# Because below we are using `windows_aarch64` platform, we have to define various
162+
# properties for it.
163+
pip.default(
164+
arch_name = "aarch64",
165+
config_settings = [
166+
"@platforms//os:windows",
167+
"@platforms//cpu:aarch64",
168+
],
169+
env = {
170+
"platform_version": "0",
171+
},
172+
os_name = "windows",
173+
platform = "windows_aarch64",
174+
whl_abi_tags = [], # default to all ABIs
175+
whl_platform_tags = ["win_amd64"],
176+
)
177+
161178
# To fetch pip dependencies, use pip.parse. We can pass in various options,
162179
# but typically we pass requirements and the Python version. The Python
163180
# version must have been configured by a corresponding `python.toolchain()`

python/private/pypi/BUILD.bazel

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,11 @@ bzl_library(
116116
":parse_whl_name_bzl",
117117
":pep508_env_bzl",
118118
":pip_repository_attrs_bzl",
119+
":python_tag_bzl",
119120
":simpleapi_download_bzl",
120121
":whl_config_setting_bzl",
121122
":whl_library_bzl",
122123
":whl_repo_name_bzl",
123-
":whl_target_platforms_bzl",
124124
"//python/private:full_version_bzl",
125125
"//python/private:normalize_name_bzl",
126126
"//python/private:version_bzl",
@@ -209,7 +209,7 @@ bzl_library(
209209
":parse_requirements_txt_bzl",
210210
":pypi_repo_utils_bzl",
211211
":requirements_files_by_platform_bzl",
212-
":whl_target_platforms_bzl",
212+
":select_whl_bzl",
213213
"//python/private:normalize_name_bzl",
214214
"//python/private:repo_utils_bzl",
215215
],
@@ -438,5 +438,4 @@ bzl_library(
438438
bzl_library(
439439
name = "whl_target_platforms_bzl",
440440
srcs = ["whl_target_platforms.bzl"],
441-
deps = [":parse_whl_name_bzl"],
442441
)

python/private/pypi/evaluate_markers.bzl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@ def evaluate_markers(*, requirements, platforms):
4343
for req_string, platform_strings in requirements.items():
4444
req = requirement(req_string)
4545
for platform_str in platform_strings:
46-
env = platforms.get(platform_str)
47-
if not env:
46+
plat = platforms.get(platform_str)
47+
if not plat:
4848
fail("Please define platform: '{}'".format(platform_str))
4949

50-
if evaluate(req.marker, env = env):
50+
if evaluate(req.marker, env = plat.env):
5151
ret.setdefault(req_string, []).append(platform_str)
5252

5353
return ret

0 commit comments

Comments
 (0)