Skip to content

Commit 2008f0b

Browse files
authored
Fixed 32-bit platform tag detection (#560)
- use `struct.calcsize("P") == 4` rather than `sys.maxsize == 2147483647` - extend the 32bit check to `linux-aarch64` => `linux-armv7l`
1 parent 2bf5bb0 commit 2008f0b

File tree

4 files changed

+53
-13
lines changed

4 files changed

+53
-13
lines changed

docs/news.rst

+5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
Release Notes
22
=============
33

4+
**UNRELEASED**
5+
6+
- Fixed platform tag detection for GraalPy and 32-bit python running on an aarch64
7+
kernel (PR by Matthieu Darbois)
8+
49
**0.41.1 (2023-08-05)**
510

611
- Fixed naming of the ``data_dir`` directory in the presence of local version segment

src/wheel/bdist_wheel.py

+21-8
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import re
1111
import shutil
1212
import stat
13+
import struct
1314
import sys
1415
import sysconfig
1516
import warnings
@@ -57,6 +58,10 @@ def safe_version(version):
5758
PY_LIMITED_API_PATTERN = r"cp3\d"
5859

5960

61+
def _is_32bit_interpreter():
62+
return struct.calcsize("P") == 4
63+
64+
6065
def python_tag():
6166
return f"py{sys.version_info[0]}"
6267

@@ -66,9 +71,15 @@ def get_platform(archive_root):
6671
result = sysconfig.get_platform()
6772
if result.startswith("macosx") and archive_root is not None:
6873
result = calculate_macosx_platform_tag(archive_root, result)
69-
elif result == "linux-x86_64" and sys.maxsize == 2147483647:
70-
# pip pull request #3497
71-
result = "linux-i686"
74+
elif _is_32bit_interpreter():
75+
if result == "linux-x86_64":
76+
# pip pull request #3497
77+
result = "linux-i686"
78+
elif result == "linux-aarch64":
79+
# packaging pull request #234
80+
# TODO armv8l, packaging pull request #690 => this did not land
81+
# in pip/packaging yet
82+
result = "linux-armv7l"
7283

7384
return result.replace("-", "_")
7485

@@ -300,11 +311,13 @@ def get_tag(self):
300311
# modules, use the default platform name.
301312
plat_name = get_platform(self.bdist_dir)
302313

303-
if (
304-
plat_name in ("linux-x86_64", "linux_x86_64")
305-
and sys.maxsize == 2147483647
306-
):
307-
plat_name = "linux_i686"
314+
if _is_32bit_interpreter():
315+
if plat_name in ("linux-x86_64", "linux_x86_64"):
316+
plat_name = "linux_i686"
317+
if plat_name in ("linux-aarch64", "linux_aarch64"):
318+
# TODO armv8l, packaging pull request #690 => this did not land
319+
# in pip/packaging yet
320+
plat_name = "linux_armv7l"
308321

309322
plat_name = (
310323
plat_name.lower().replace("-", "_").replace(".", "_").replace(" ", "_")

tests/test_bdist_wheel.py

+16
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import os.path
44
import shutil
55
import stat
6+
import struct
67
import subprocess
78
import sys
89
import sysconfig
@@ -11,6 +12,7 @@
1112
from zipfile import ZipFile
1213

1314
import pytest
15+
import setuptools
1416

1517
from wheel.bdist_wheel import (
1618
bdist_wheel,
@@ -385,3 +387,17 @@ def test_data_dir_with_tag_build(monkeypatch, tmp_path):
385387
"test-1.0.dist-info/WHEEL",
386388
):
387389
assert not_expected not in entries
390+
391+
392+
@pytest.mark.parametrize(
393+
"reported,expected",
394+
[("linux-x86_64", "linux_i686"), ("linux-aarch64", "linux_armv7l")],
395+
)
396+
def test_platform_linux32(reported, expected, monkeypatch):
397+
monkeypatch.setattr(struct, "calcsize", lambda x: 4)
398+
dist = setuptools.Distribution()
399+
cmd = bdist_wheel(dist)
400+
cmd.plat_name = reported
401+
cmd.root_is_pure = False
402+
_, _, actual = cmd.get_tag()
403+
assert actual == expected

tests/test_macosx_libfile.py

+11-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
from __future__ import annotations
22

33
import os
4-
import sys
4+
import struct
55
import sysconfig
66

7+
import pytest
8+
79
from wheel.bdist_wheel import get_platform
810
from wheel.macosx_libfile import extract_macosx_min_system_version
911

@@ -214,7 +216,11 @@ def test_get_platform_bigsur_platform(self, monkeypatch):
214216
assert get_platform(dylib_dir) == "macosx_11_0_x86_64"
215217

216218

217-
def test_get_platform_linux(monkeypatch):
218-
monkeypatch.setattr(sysconfig, "get_platform", return_factory("linux-x86_64"))
219-
monkeypatch.setattr(sys, "maxsize", 2147483647)
220-
assert get_platform(None) == "linux_i686"
219+
@pytest.mark.parametrize(
220+
"reported,expected",
221+
[("linux-x86_64", "linux_i686"), ("linux-aarch64", "linux_armv7l")],
222+
)
223+
def test_get_platform_linux32(reported, expected, monkeypatch):
224+
monkeypatch.setattr(sysconfig, "get_platform", return_factory(reported))
225+
monkeypatch.setattr(struct, "calcsize", lambda x: 4)
226+
assert get_platform(None) == expected

0 commit comments

Comments
 (0)