Skip to content

Commit be3818a

Browse files
authored
Add support for Android tags (#13303)
Android is an officially supported Python platform since Python 3.13.
1 parent d14ace5 commit be3818a

File tree

3 files changed

+64
-0
lines changed

3 files changed

+64
-0
lines changed

news/13299.feature.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Support for :pep:`738` Android wheels.

src/pip/_internal/utils/compatibility_tags.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from pip._vendor.packaging.tags import (
77
PythonVersion,
88
Tag,
9+
android_platforms,
910
compatible_tags,
1011
cpython_tags,
1112
generic_tags,
@@ -63,6 +64,16 @@ def _ios_platforms(arch: str) -> List[str]:
6364
return arches
6465

6566

67+
def _android_platforms(arch: str) -> List[str]:
68+
match = re.fullmatch(r"android_(\d+)_(.+)", arch)
69+
if match:
70+
api_level, abi = match.groups()
71+
return list(android_platforms(int(api_level), abi))
72+
else:
73+
# arch pattern didn't match (?!)
74+
return [arch]
75+
76+
6677
def _custom_manylinux_platforms(arch: str) -> List[str]:
6778
arches = [arch]
6879
arch_prefix, arch_sep, arch_suffix = arch.partition("_")
@@ -90,6 +101,8 @@ def _get_custom_platforms(arch: str) -> List[str]:
90101
arches = _mac_platforms(arch)
91102
elif arch.startswith("ios"):
92103
arches = _ios_platforms(arch)
104+
elif arch_prefix == "android":
105+
arches = _android_platforms(arch)
93106
elif arch_prefix in ["manylinux2014", "manylinux2010"]:
94107
arches = _custom_manylinux_platforms(arch)
95108
else:

tests/unit/test_models_wheel.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,56 @@ def test_not_supported_ios_version(self) -> None:
180180
w = Wheel("simple-0.1-cp313-none-ios_15_1_arm64_iphoneos.whl")
181181
assert not w.supported(tags=tags)
182182

183+
def test_android(self) -> None:
184+
arm_old = compatibility_tags.get_supported(
185+
"313", platforms=["android_21_arm64_v8a"], impl="cp"
186+
)
187+
arm_new = compatibility_tags.get_supported(
188+
"313", platforms=["android_30_arm64_v8a"], impl="cp"
189+
)
190+
x86_old = compatibility_tags.get_supported(
191+
"313", platforms=["android_21_x86_64"], impl="cp"
192+
)
193+
x86_new = compatibility_tags.get_supported(
194+
"313", platforms=["android_30_x86_64"], impl="cp"
195+
)
196+
197+
w = Wheel("simple-0.1-cp313-none-android_21_arm64_v8a.whl")
198+
assert w.supported(arm_old)
199+
assert w.supported(arm_new)
200+
assert not w.supported(x86_old)
201+
assert not w.supported(x86_new)
202+
203+
w = Wheel("simple-0.1-cp313-none-android_22_arm64_v8a.whl")
204+
assert not w.supported(arm_old)
205+
assert w.supported(arm_new)
206+
assert not w.supported(x86_old)
207+
assert not w.supported(x86_new)
208+
209+
w = Wheel("simple-0.1-cp313-none-android_31_arm64_v8a.whl")
210+
assert not w.supported(arm_old)
211+
assert not w.supported(arm_new)
212+
assert not w.supported(x86_old)
213+
assert not w.supported(x86_new)
214+
215+
w = Wheel("simple-0.1-cp313-none-android_20_x86_64.whl")
216+
assert not w.supported(arm_old)
217+
assert not w.supported(arm_new)
218+
assert w.supported(x86_old)
219+
assert w.supported(x86_new)
220+
221+
w = Wheel("simple-0.1-cp313-none-android_30_x86_64.whl")
222+
assert not w.supported(arm_old)
223+
assert not w.supported(arm_new)
224+
assert not w.supported(x86_old)
225+
assert w.supported(x86_new)
226+
227+
w = Wheel("simple-0.1-cp313-none-android_31_x86_64.whl")
228+
assert not w.supported(arm_old)
229+
assert not w.supported(arm_new)
230+
assert not w.supported(x86_old)
231+
assert not w.supported(x86_new)
232+
183233
def test_support_index_min(self) -> None:
184234
"""
185235
Test results from `support_index_min`

0 commit comments

Comments
 (0)