Skip to content

Commit

Permalink
Support PEP 738
Browse files Browse the repository at this point in the history
  • Loading branch information
di committed Feb 4, 2025
1 parent 07fc14b commit 0ff1aa5
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 2 deletions.
4 changes: 4 additions & 0 deletions tests/unit/forklift/test_legacy.py
Original file line number Diff line number Diff line change
Expand Up @@ -2732,6 +2732,10 @@ def test_upload_attestation_fails_without_oidc_publisher(
"macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64."
"macosx_10_10_intel.macosx_10_10_x86_64"
),
"android_21_armeabi_v7a",
"android_21_arm64_v8a",
"android_21_x86",
"android_21_x86_64",
],
)
def test_upload_succeeds_with_wheel(
Expand Down
16 changes: 16 additions & 0 deletions tests/unit/utils/test_wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,22 @@
("foo-0.0.0-jy38-none-any.whl", ["Jython 3.8"]),
("foo-0.0.0-garbage-none-any.whl", ["garbage"]),
("foo-0.0.0-69-none-any.whl", []),
(
"foo-0.0.0-py3-none-android_21_armeabi_v7a.whl",
["Android 21+ ARMv7", "Python 3"],
),
(
"foo-0.0.0-py3-none-android_21_arm64_v8a.whl",
["Android 21+ ARMv8", "Python 3"],
),
(
"foo-0.0.0-py3-none-android_21_x86.whl",
["Android 21+ x86", "Python 3"],
),
(
"foo-0.0.0-py3-none-android_21_x86_64.whl",
["Android 21+ x86-64", "Python 3"],
),
],
)
def test_wheel_to_pretty_tags(filename, expected_tags):
Expand Down
21 changes: 21 additions & 0 deletions warehouse/forklift/legacy.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,23 +167,44 @@
_manylinux_arches = _jointlinux_arches | {"ppc64"}
_musllinux_arches = _jointlinux_arches

# PEP 738: Adding Android as a supported platform
_android_platform_re = re.compile(r"android_(?P<api_level>\d+)_(?P<arch>.*)")
_android_api_levels = {str(level) for level in range(21, 99)}
_android_arches = {
"armeabi_v7a",
"arm64_v8a",
"x86",
"x86_64",
}


# Actual checking code;
def _valid_platform_tag(platform_tag):
if platform_tag in _allowed_platforms:
return True

m = _macosx_platform_re.match(platform_tag)
if (
m
and m.group("major") in _macosx_major_versions
and m.group("arch") in _macosx_arches
):
return True

m = _linux_platform_re.match(platform_tag)
if m and m.group("libc") == "musl":
return m.group("arch") in _musllinux_arches
if m and m.group("libc") == "many":
return m.group("arch") in _manylinux_arches

m = _android_platform_re.match(platform_tag)
if (
m
and m.group("api_level") in _android_api_levels
and m.group("arch") in _android_arches
):
return True

return False


Expand Down
9 changes: 7 additions & 2 deletions warehouse/utils/wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@

import packaging.utils

# import sentry_sdk

_PLATFORMS = [
(re.compile(r"^win_(.*?)$"), lambda m: f"Windows {_normalize_arch(m.group(1))}"),
(re.compile(r"^win32$"), lambda m: "Windows x86"),
Expand All @@ -40,6 +38,10 @@
re.compile(r"^macosx_(\d+)_(\d+)_(.*?)$"),
lambda m: f"macOS {m.group(1)}.{m.group(2)}+ {_normalize_arch(m.group(3))}",
),
(
re.compile(r"^android_(\d+)_(.*?)$"),
lambda m: f"Android {m.group(1)}+ {_normalize_arch(m.group(2))}",
),
]

_ARCHS = {
Expand All @@ -49,6 +51,9 @@
"universal2": "universal2 (ARM64, x86-64)",
"arm64": "ARM64",
"armv7l": "ARMv7l",
"armeabi_v7a": "ARMv7",
"arm64_v8a": "ARMv8",
"x86": "x86",
}


Expand Down

0 comments on commit 0ff1aa5

Please sign in to comment.