Skip to content

Commit b00d7a2

Browse files
committed
extra fixes and add a helper for python_tag
1 parent 818f3e3 commit b00d7a2

File tree

5 files changed

+43
-23
lines changed

5 files changed

+43
-23
lines changed

python/private/pypi/BUILD.bazel

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ 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",
@@ -337,6 +338,11 @@ bzl_library(
337338
],
338339
)
339340

341+
bzl_library(
342+
name = "python_tag_bzl",
343+
srcs = ["python_tag.bzl"],
344+
)
345+
340346
bzl_library(
341347
name = "render_pkg_aliases_bzl",
342348
srcs = ["render_pkg_aliases.bzl"],
@@ -363,6 +369,7 @@ bzl_library(
363369
srcs = ["select_whl.bzl"],
364370
deps = [
365371
":parse_whl_name_bzl",
372+
":python_tag_bzl",
366373
"//python/private:version_bzl",
367374
],
368375
)

python/private/pypi/extension.bzl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ load(":parse_requirements.bzl", "parse_requirements")
3131
load(":parse_whl_name.bzl", "parse_whl_name")
3232
load(":pep508_env.bzl", "env")
3333
load(":pip_repository_attrs.bzl", "ATTRS")
34+
load(":python_tag.bzl", "python_tag")
3435
load(":requirements_files_by_platform.bzl", "requirements_files_by_platform")
3536
load(":simpleapi_download.bzl", "simpleapi_download")
3637
load(":whl_config_setting.bzl", "whl_config_setting")
@@ -77,8 +78,7 @@ def _platforms(*, python_version, minor_mapping, config):
7778
)
7879

7980
for platform, values in config.platforms.items():
80-
# TODO @aignas 2025-07-07: fix the logic here
81-
implementation = values.env["implementation_name"][:2].lower()
81+
implementation = python_tag(values.env["implementation_name"])
8282

8383
# TODO @aignas 2025-07-07: move the abi construction somewhere else
8484
abi = "{impl}{0}{1}.{2}".format(

python/private/pypi/pep508_env.bzl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,16 +67,16 @@ platform_machine_select_map = {
6767
# Platform system returns results from the `uname` call.
6868
platform_system_select_map = {
6969
# See https://peps.python.org/pep-0738/#platform
70-
"android": "Android",
71-
"freebsd": "FreeBSD",
70+
"@platforms//os:android": "Android",
71+
"@platforms//os:freebsd": "FreeBSD",
7272
# See https://peps.python.org/pep-0730/#platform
7373
# NOTE: Per Pep 730, "iPadOS" is also an acceptable value
74-
"ios": "iOS",
75-
"linux": "Linux",
76-
"netbsd": "NetBSD",
77-
"openbsd": "OpenBSD",
78-
"osx": "Darwin",
79-
"windows": "Windows",
74+
"@platforms//os:ios": "iOS",
75+
"@platforms//os:linux": "Linux",
76+
"@platforms//os:netbsd": "NetBSD",
77+
"@platforms//os:openbsd": "OpenBSD",
78+
"@platforms//os:osx": "Darwin",
79+
"@platforms//os:windows": "Windows",
8080
# The value is empty string if it cannot be determined:
8181
# https://docs.python.org/3/library/platform.html#platform.machine
8282
_DEFAULT: "",

python/private/pypi/python_tag.bzl

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
"A simple utility function to get the python_tag from the implementation name"
2+
3+
# Taken from
4+
# https://packaging.python.org/en/latest/specifications/platform-compatibility-tags/#python-tag
5+
_PY_TAGS = {
6+
# "py": Generic Python (does not require implementation-specific features)
7+
"cpython": "cp",
8+
"ironpython": "ip",
9+
"jython": "jy",
10+
"pypy": "pp",
11+
}
12+
PY_TAG_GENERIC = "py"
13+
14+
def python_tag(implementation_name):
15+
"""Get the python_tag from the implementation_name.
16+
17+
Args:
18+
implementation_name: {type}`str` the implementation name, e.g. "cpython"
19+
20+
Returns:
21+
A {type}`str` that represents the python_tag.
22+
"""
23+
return _PY_TAGS.get(implementation_name, implementation_name)

python/private/pypi/select_whl.bzl

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,7 @@
22

33
load("//python/private:version.bzl", "version")
44
load(":parse_whl_name.bzl", "parse_whl_name")
5-
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"
5+
load(":python_tag.bzl", "PY_TAG_GENERIC", "python_tag")
166

177
def _get_priority(*, tag, values, allow_wildcard = True):
188
for priority, wp in enumerate(values):
@@ -51,12 +41,12 @@ def select_whl(*, whls, python_version, platforms, want_abis, implementation_nam
5141
"""
5242
py_version = version.parse(python_version, strict = True)
5343
candidates = {}
54-
implementation = _PY_TAGS.get(implementation_name, implementation_name)
44+
implementation = python_tag(implementation_name)
5545

5646
for whl in whls:
5747
parsed = parse_whl_name(whl.filename)
5848

59-
if parsed.python_tag.startswith(_PY):
49+
if parsed.python_tag.startswith(PY_TAG_GENERIC):
6050
pass
6151
elif not parsed.python_tag.startswith(implementation):
6252
if logger:

0 commit comments

Comments
 (0)