Skip to content

Commit 4890805

Browse files
committed
remove the arbitrary 2 letter truncation for implementation_name and use the standard
1 parent 1f7a6d2 commit 4890805

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

python/private/pypi/parse_requirements.bzl

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -411,16 +411,14 @@ def _add_dists(*, requirement, index_urls, target_platform, logger = None):
411411
]))
412412

413413
if not target_platform:
414-
# The pipstar platforms are undefined here
415-
# TODO @aignas 2025-07-05: should we fail hard? It should only be the case in unit
416-
# tests or maybe WORKSPACE.
414+
# The pipstar platforms are undefined here, so we cannot do any matching
417415
return sdist
418416

419417
# Select a single wheel that can work on the target_platform
420418
return select_whl(
421419
whls = whls,
422420
python_version = target_platform.env["python_full_version"],
423-
implementation = target_platform.env["implementation_name"][:2],
421+
implementation_name = target_platform.env["implementation_name"],
424422
want_abis = target_platform.want_abis,
425423
platforms = target_platform.platform_tags,
426424
logger = logger,

python/private/pypi/select_whl.bzl

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,17 @@
33
load("//python/private:version.bzl", "version")
44
load(":parse_whl_name.bzl", "parse_whl_name")
55

6+
# Taken from
7+
# https://packaging.python.org/en/latest/specifications/platform-compatibility-tags/#python-tag
8+
_PY_TAGS = {
9+
# "py": Generic Python (does not require implementation-specific features)
10+
"cpython": "cp",
11+
"ironpython": "ip",
12+
"jython": "jy",
13+
"pypy": "pp",
14+
}
15+
_PY = "py"
16+
617
def _get_priority(*, tag, values, allow_wildcard = True):
718
for priority, wp in enumerate(values):
819
head, sep, tail = wp.partition("*")
@@ -19,7 +30,7 @@ def _get_priority(*, tag, values, allow_wildcard = True):
1930

2031
return None
2132

22-
def select_whl(*, whls, python_version, platforms, want_abis, implementation = "cp", limit = 1, logger = None):
33+
def select_whl(*, whls, python_version, platforms, want_abis, implementation_name = "cpython", limit = 1, logger = None):
2334
"""Select a whl that is the most suitable for the given platform.
2435
2536
Args:
@@ -28,7 +39,7 @@ def select_whl(*, whls, python_version, platforms, want_abis, implementation = "
2839
python_version: {type}`str` the target python version.
2940
platforms: {type}`list[str]` the target platform identifiers that may contain
3041
a single `*` character.
31-
implementation: {type}`str` a 2 letter implementation name. Defaults to "cp"
42+
implementation_name: {type}`str` the `implementation_name` from the target_platform env.
3243
want_abis: {type}`str` the ABIs that the target_platform is compatible with.
3344
limit: {type}`int` number of wheels to return. Defaults to 1.
3445
logger: {type}`struct` the logger instance.
@@ -40,11 +51,12 @@ def select_whl(*, whls, python_version, platforms, want_abis, implementation = "
4051
"""
4152
py_version = version.parse(python_version, strict = True)
4253
candidates = {}
54+
implementation = _PY_TAGS.get(implementation_name, implementation_name)
4355

4456
for whl in whls:
4557
parsed = parse_whl_name(whl.filename)
4658

47-
if parsed.python_tag.startswith("py"):
59+
if parsed.python_tag.startswith(_PY):
4860
pass
4961
elif not parsed.python_tag.startswith(implementation):
5062
if logger:
@@ -57,7 +69,7 @@ def select_whl(*, whls, python_version, platforms, want_abis, implementation = "
5769
if parsed.python_tag == "py2.py3":
5870
min_version = "2"
5971
else:
60-
min_version = parsed.python_tag[2:]
72+
min_version = parsed.python_tag[len(implementation):]
6173

6274
if len(min_version) > 1:
6375
min_version = "{}.{}".format(min_version[0], min_version[1:])

0 commit comments

Comments
 (0)