Skip to content

Commit 1e84e40

Browse files
committed
fix examples and add more test cases
1 parent c95dce6 commit 1e84e40

File tree

5 files changed

+65
-23
lines changed

5 files changed

+65
-23
lines changed

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+
platform_tags = ["win_amd64"],
175+
want_abis = [], # default to all ABIs
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/extension.bzl

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ def _whl_repo(*, src, whl_library_args, is_multiple_versions, download_only, net
392392
def _configure(config, *, platform, os_name, arch_name, config_settings, env = {}, want_abis, platform_tags, override = False):
393393
"""Set the value in the config if the value is provided"""
394394
config.setdefault("platforms", {})
395-
if platform:
395+
if platform and (os_name or arch_name or config_settings or platform_tags or env):
396396
if not override and config.get("platforms", {}).get(platform):
397397
return
398398

@@ -429,9 +429,12 @@ def _configure(config, *, platform, os_name, arch_name, config_settings, env = {
429429
else:
430430
config["platforms"].pop(platform)
431431

432-
def _create_config(defaults):
433-
if defaults["platforms"]:
434-
return struct(**defaults)
432+
def _set_defaults(defaults):
433+
"""Set defaults that rules_python is operating under.
434+
435+
Because this code is also tested in unit tests, leaving it in MODULE.bazel would be
436+
a little problematic.
437+
"""
435438

436439
# NOTE: We have this so that it is easier to maintain unit tests assuming certain
437440
# defaults
@@ -488,22 +491,24 @@ def _create_config(defaults):
488491
},
489492
)
490493

491-
_configure(
492-
defaults,
493-
arch_name = "x86_64",
494-
os_name = "windows",
495-
platform = "windows_x86_64",
496-
config_settings = [
497-
"@platforms//os:windows",
498-
"@platforms//cpu:x86_64",
499-
],
500-
want_abis = [],
501-
platform_tags = ["win_amd64"],
502-
env = {
503-
"platform_version": "0",
504-
},
505-
)
506-
return struct(**defaults)
494+
for cpu, platform_tags in {
495+
"x86_64": ["win_amd64"],
496+
}.items():
497+
_configure(
498+
defaults,
499+
arch_name = cpu,
500+
os_name = "windows",
501+
platform = "windows_{}".format(cpu),
502+
config_settings = [
503+
"@platforms//os:windows",
504+
"@platforms//cpu:{}".format(cpu),
505+
],
506+
want_abis = [],
507+
platform_tags = platform_tags,
508+
env = {
509+
"platform_version": "0",
510+
},
511+
)
507512

508513
def parse_modules(
509514
module_ctx,
@@ -559,6 +564,7 @@ You cannot use both the additive_build_content and additive_build_content_file a
559564
"enable_pipstar": enable_pipstar,
560565
"platforms": {},
561566
}
567+
_set_defaults(defaults)
562568
for mod in module_ctx.modules:
563569
if not (mod.is_root or mod.name == "rules_python"):
564570
continue
@@ -582,7 +588,7 @@ You cannot use both the additive_build_content and additive_build_content_file a
582588
# * for whl selection - We could also model the `cp313t` freethreaded as separate platforms.
583589
)
584590

585-
config = _create_config(defaults)
591+
config = struct(**defaults)
586592

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

python/private/pypi/whl_target_platforms.bzl

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,15 @@ def select_whl(*, whls, python_version, platforms, want_abis, implementation = "
9494
suffix = ""
9595
if parsed.abi_tag.startswith(implementation):
9696
v = parsed.abi_tag[2:]
97-
9897
min_whl_py_version = version.parse(
99-
"{}.{}".format(v[0], v[1:].strip("tm")),
98+
"{}.{}".format(v[0], v[1:].strip("tmu")),
10099
strict = False,
101100
)
101+
if not min_whl_py_version:
102+
if logger:
103+
logger.warn(lambda: "Discarding the wheel ('{}') because we could not parse the version from the abi tag".format(whl.filename))
104+
continue
105+
102106
if parsed.abi_tag.endswith("t"):
103107
suffix = "t"
104108

tests/pypi/extension/extension_tests.bzl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1067,6 +1067,18 @@ def _test_pipstar_platforms(env):
10671067
("linux", "x86_64"),
10681068
("osx", "aarch64"),
10691069
]
1070+
] + [
1071+
_default(platform = name)
1072+
for name in [
1073+
"linux_x86_64",
1074+
"linux_aarch64",
1075+
"linux_arm",
1076+
"linux_ppc",
1077+
"linux_s390x",
1078+
"osx_x86_64",
1079+
"osx_aarch64",
1080+
"windows_x86_64",
1081+
]
10701082
],
10711083
parse = [
10721084
_parse(

tests/pypi/whl_target_platforms/select_whl_tests.bzl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ WHL_LIST = [
7070
"pkg-0.0.1-py310-abi3-any.whl",
7171
"pkg-0.0.1-py3-abi3-any.whl",
7272
"pkg-0.0.1-py3-none-any.whl",
73+
# Extra examples that should be discarded
74+
"pkg-0.0.1-py27-cp27mu-win_amd64.whl",
75+
"pkg-0.0.1-pp310-pypy310_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl",
7376
]
7477

7578
def _match(env, got, *want_filenames):

0 commit comments

Comments
 (0)