Skip to content

Commit 4143903

Browse files
authored
refactor(pypi): move the platform config to MODULE.bazel (bazel-contrib#3064)
This splits the configuration that we have for the `rules_python` and the defaults that we set for our users from the actual unit tests where we check that the extension is working correctly. With this we will be able to dog food the API and point users into the `MODULE.bazel` as the example snippet. Work towards bazel-contrib#2949 Work towards bazel-contrib#2747
1 parent 2690e3f commit 4143903

File tree

3 files changed

+115
-133
lines changed

3 files changed

+115
-133
lines changed

MODULE.bazel

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,62 @@ register_toolchains("@pythons_hub//:all")
6060
# Install twine for our own runfiles wheel publishing and allow bzlmod users to use it.
6161

6262
pip = use_extension("//python/extensions:pip.bzl", "pip")
63+
64+
# NOTE @aignas 2025-07-06: we define these platforms to keep backwards compatibility with the
65+
# current `experimental_index_url` implementation. Whilst we stabilize the API this list may be
66+
# updated with a mention in the CHANGELOG.
67+
[
68+
pip.default(
69+
arch_name = cpu,
70+
config_settings = [
71+
"@platforms//cpu:{}".format(cpu),
72+
"@platforms//os:linux",
73+
],
74+
env = {"platform_version": "0"},
75+
os_name = "linux",
76+
platform = "linux_{}".format(cpu),
77+
)
78+
for cpu in [
79+
"x86_64",
80+
"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",
87+
]
88+
]
89+
90+
[
91+
pip.default(
92+
arch_name = cpu,
93+
config_settings = [
94+
"@platforms//cpu:{}".format(cpu),
95+
"@platforms//os:osx",
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": "14.0"},
100+
os_name = "osx",
101+
platform = "osx_{}".format(cpu),
102+
)
103+
for cpu in [
104+
"aarch64",
105+
"x86_64",
106+
]
107+
]
108+
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+
)
63119
pip.parse(
64120
# NOTE @aignas 2024-10-26: We have an integration test that depends on us
65121
# being able to build sdists for this hub, so explicitly set this to False.

python/private/pypi/extension.bzl

Lines changed: 1 addition & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -393,64 +393,6 @@ def _configure(config, *, platform, os_name, arch_name, config_settings, env = {
393393
else:
394394
config["platforms"].pop(platform)
395395

396-
def _create_config(defaults):
397-
if defaults["platforms"]:
398-
return struct(**defaults)
399-
400-
# NOTE: We have this so that it is easier to maintain unit tests assuming certain
401-
# defaults
402-
for cpu in [
403-
"x86_64",
404-
"aarch64",
405-
# TODO @aignas 2025-05-19: only leave tier 0-1 cpus when stabilizing the
406-
# `pip.default` extension. i.e. drop the below values - users will have to
407-
# define themselves if they need them.
408-
"arm",
409-
"ppc",
410-
"s390x",
411-
]:
412-
_configure(
413-
defaults,
414-
arch_name = cpu,
415-
os_name = "linux",
416-
platform = "linux_{}".format(cpu),
417-
config_settings = [
418-
"@platforms//os:linux",
419-
"@platforms//cpu:{}".format(cpu),
420-
],
421-
env = {"platform_version": "0"},
422-
)
423-
for cpu in [
424-
"aarch64",
425-
"x86_64",
426-
]:
427-
_configure(
428-
defaults,
429-
arch_name = cpu,
430-
# We choose the oldest non-EOL version at the time when we release `rules_python`.
431-
# See https://endoflife.date/macos
432-
os_name = "osx",
433-
platform = "osx_{}".format(cpu),
434-
config_settings = [
435-
"@platforms//os:osx",
436-
"@platforms//cpu:{}".format(cpu),
437-
],
438-
env = {"platform_version": "14.0"},
439-
)
440-
441-
_configure(
442-
defaults,
443-
arch_name = "x86_64",
444-
os_name = "windows",
445-
platform = "windows_x86_64",
446-
config_settings = [
447-
"@platforms//os:windows",
448-
"@platforms//cpu:x86_64",
449-
],
450-
env = {"platform_version": "0"},
451-
)
452-
return struct(**defaults)
453-
454396
def parse_modules(
455397
module_ctx,
456398
_fail = fail,
@@ -527,7 +469,7 @@ You cannot use both the additive_build_content and additive_build_content_file a
527469
# for what. We could also model the `cp313t` freethreaded as separate platforms.
528470
)
529471

530-
config = _create_config(defaults)
472+
config = struct(**defaults)
531473

532474
# TODO @aignas 2025-06-03: Merge override API with the builder?
533475
_overriden_whl_set = {}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy