Skip to content

Commit

Permalink
Fixed 32-bit platform tag detection (#560)
Browse files Browse the repository at this point in the history
- use `struct.calcsize("P") == 4` rather than `sys.maxsize == 2147483647`
- extend the 32bit check to `linux-aarch64` => `linux-armv7l`
  • Loading branch information
mayeut authored Aug 21, 2023
1 parent 2bf5bb0 commit 2008f0b
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 13 deletions.
5 changes: 5 additions & 0 deletions docs/news.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
Release Notes
=============

**UNRELEASED**

- Fixed platform tag detection for GraalPy and 32-bit python running on an aarch64
kernel (PR by Matthieu Darbois)

**0.41.1 (2023-08-05)**

- Fixed naming of the ``data_dir`` directory in the presence of local version segment
Expand Down
29 changes: 21 additions & 8 deletions src/wheel/bdist_wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import re
import shutil
import stat
import struct
import sys
import sysconfig
import warnings
Expand Down Expand Up @@ -57,6 +58,10 @@ def safe_version(version):
PY_LIMITED_API_PATTERN = r"cp3\d"


def _is_32bit_interpreter():
return struct.calcsize("P") == 4


def python_tag():
return f"py{sys.version_info[0]}"

Expand All @@ -66,9 +71,15 @@ def get_platform(archive_root):
result = sysconfig.get_platform()
if result.startswith("macosx") and archive_root is not None:
result = calculate_macosx_platform_tag(archive_root, result)
elif result == "linux-x86_64" and sys.maxsize == 2147483647:
# pip pull request #3497
result = "linux-i686"
elif _is_32bit_interpreter():
if result == "linux-x86_64":
# pip pull request #3497
result = "linux-i686"
elif result == "linux-aarch64":
# packaging pull request #234
# TODO armv8l, packaging pull request #690 => this did not land
# in pip/packaging yet
result = "linux-armv7l"

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

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

if (
plat_name in ("linux-x86_64", "linux_x86_64")
and sys.maxsize == 2147483647
):
plat_name = "linux_i686"
if _is_32bit_interpreter():
if plat_name in ("linux-x86_64", "linux_x86_64"):
plat_name = "linux_i686"
if plat_name in ("linux-aarch64", "linux_aarch64"):
# TODO armv8l, packaging pull request #690 => this did not land
# in pip/packaging yet
plat_name = "linux_armv7l"

plat_name = (
plat_name.lower().replace("-", "_").replace(".", "_").replace(" ", "_")
Expand Down
16 changes: 16 additions & 0 deletions tests/test_bdist_wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import os.path
import shutil
import stat
import struct
import subprocess
import sys
import sysconfig
Expand All @@ -11,6 +12,7 @@
from zipfile import ZipFile

import pytest
import setuptools

from wheel.bdist_wheel import (
bdist_wheel,
Expand Down Expand Up @@ -385,3 +387,17 @@ def test_data_dir_with_tag_build(monkeypatch, tmp_path):
"test-1.0.dist-info/WHEEL",
):
assert not_expected not in entries


@pytest.mark.parametrize(
"reported,expected",
[("linux-x86_64", "linux_i686"), ("linux-aarch64", "linux_armv7l")],
)
def test_platform_linux32(reported, expected, monkeypatch):
monkeypatch.setattr(struct, "calcsize", lambda x: 4)
dist = setuptools.Distribution()
cmd = bdist_wheel(dist)
cmd.plat_name = reported
cmd.root_is_pure = False
_, _, actual = cmd.get_tag()
assert actual == expected
16 changes: 11 additions & 5 deletions tests/test_macosx_libfile.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
from __future__ import annotations

import os
import sys
import struct
import sysconfig

import pytest

from wheel.bdist_wheel import get_platform
from wheel.macosx_libfile import extract_macosx_min_system_version

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


def test_get_platform_linux(monkeypatch):
monkeypatch.setattr(sysconfig, "get_platform", return_factory("linux-x86_64"))
monkeypatch.setattr(sys, "maxsize", 2147483647)
assert get_platform(None) == "linux_i686"
@pytest.mark.parametrize(
"reported,expected",
[("linux-x86_64", "linux_i686"), ("linux-aarch64", "linux_armv7l")],
)
def test_get_platform_linux32(reported, expected, monkeypatch):
monkeypatch.setattr(sysconfig, "get_platform", return_factory(reported))
monkeypatch.setattr(struct, "calcsize", lambda x: 4)
assert get_platform(None) == expected

0 comments on commit 2008f0b

Please sign in to comment.