Skip to content

Commit 132124c

Browse files
committed
do some whl_platform_tag processing
1 parent 6b1fc22 commit 132124c

File tree

2 files changed

+45
-2
lines changed

2 files changed

+45
-2
lines changed

python/private/pypi/select_whl.bzl

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,46 @@ def _python_tag_priority(*, tag, implementation, py_version):
105105
version.key(ver),
106106
)
107107

108+
def _filter_platform_tags(tags):
109+
ret = []
110+
replacements = {}
111+
for tag in tags:
112+
if not (
113+
tag.startswith(_ANDROID) or
114+
tag.startswith(_IOS) or
115+
tag.startswith(_MACOSX) or
116+
tag.startswith(_MANYLINUX) or
117+
tag.startswith(_MUSLLINUX)
118+
):
119+
ret.append(tag)
120+
continue
121+
122+
want_os, sep, tail = tag.partition("_")
123+
if not sep:
124+
fail("could not parse the tag")
125+
126+
want_major, _, tail = tail.partition("_")
127+
if want_major == "*":
128+
# the expected match is any version
129+
want_arch = tail
130+
elif want_os.startswith(_ANDROID):
131+
want_arch = tail
132+
else:
133+
# drop the minor version segment
134+
_, _, want_arch = tail.partition("_")
135+
136+
placeholder = "{}_*_{}".format(want_os, want_arch)
137+
replacements[placeholder] = tag
138+
if placeholder in ret:
139+
ret.remove(placeholder)
140+
141+
ret.append(placeholder)
142+
143+
return [
144+
replacements.get(p, p)
145+
for p in ret
146+
]
147+
108148
def _candidates_by_priority(
109149
*,
110150
whls,
@@ -121,6 +161,9 @@ def _candidates_by_priority(
121161
"""
122162
py_version = version.parse(python_version, strict = True)
123163
implementation = python_tag(implementation_name)
164+
logger.debug(lambda: "input: {}".format(whl_platform_tags))
165+
whl_platform_tags = _filter_platform_tags(whl_platform_tags)
166+
logger.debug(lambda: "output: {}".format(whl_platform_tags))
124167

125168
ret = {}
126169
for whl in whls:

tests/pypi/select_whl/select_whl_tests.bzl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -423,12 +423,12 @@ def _test_multiple_musllinux_exact_params(env):
423423
whl_abi_tags = ["none"],
424424
python_version = "3.12",
425425
limit = 2,
426+
debug = True,
426427
)
427428
_match(
428429
env,
429430
got,
430-
# select the one with the lowest version, because of the input to the function
431-
"pkg-0.0.1-py3-none-musllinux_1_2_x86_64.whl",
431+
# 1.2 is not within the candidates because it is not compatible
432432
"pkg-0.0.1-py3-none-musllinux_1_1_x86_64.whl",
433433
)
434434

0 commit comments

Comments
 (0)