From bd475458016ad2886c57ab5e698435cb18e4e804 Mon Sep 17 00:00:00 2001 From: mayeut Date: Sun, 20 Aug 2023 13:18:08 +0200 Subject: [PATCH 1/3] fix: platform tag for GraalPy When running a 64-bit version of GraalPy (either x86_64 or aarch64), packaging returns the wrong platform tag (either i686 or armv8l). Fix this by using the same default implementation as found in stdlib platform.architecture https://github.com/python/cpython/blob/4d4393139fae39db26dead33529b6ae0bafbfc58/Lib/platform.py#L713-L716 --- src/packaging/tags.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/packaging/tags.py b/src/packaging/tags.py index 07411493..37f33b1e 100644 --- a/src/packaging/tags.py +++ b/src/packaging/tags.py @@ -4,6 +4,7 @@ import logging import platform +import struct import subprocess import sys import sysconfig @@ -37,7 +38,7 @@ } -_32_BIT_INTERPRETER = sys.maxsize <= 2**32 +_32_BIT_INTERPRETER = struct.calcsize("P") == 4 class Tag: From b9759ee4026a4f8d8dba3b60613c6db6c93b93f8 Mon Sep 17 00:00:00 2001 From: mayeut Date: Sat, 26 Aug 2023 12:19:19 +0200 Subject: [PATCH 2/3] add tests for `_32_BIT_INTERPRETER` --- tests/test_tags.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/tests/test_tags.py b/tests/test_tags.py index 870ef4ec..f8963906 100644 --- a/tests/test_tags.py +++ b/tests/test_tags.py @@ -10,9 +10,11 @@ import ctypes except ImportError: ctypes = None +import importlib import os import pathlib import platform +import struct import sys import sysconfig import types @@ -1341,3 +1343,29 @@ def test_cpython_first_none_any_tag(self, monkeypatch): interpreter = f"cp{tags.interpreter_version()}" assert tag == tags.Tag(interpreter, "none", "any") + + +class TestBitness: + def teardown_method(self): + importlib.reload(tags) + + @pytest.mark.parametrize( + "maxsize, sizeof_voidp, expected", + [ + # CPython, PyPy, pyston 64bit + (9223372036854775807, 8, False), + # GraalPy, IronPython, Jython 64bit + (2147483647, 8, False), + # CPython, PyPy, IronPython, Jython, pyodide 32bit + (2147483647, 4, True), + ], + ) + def test_32bit_interpreter(self, maxsize, sizeof_voidp, expected, monkeypatch): + def _calcsize(fmt): + assert fmt == "P" + return sizeof_voidp + + monkeypatch.setattr(sys, "maxsize", maxsize) + monkeypatch.setattr(struct, "calcsize", _calcsize) + importlib.reload(tags) + assert tags._32_BIT_INTERPRETER == expected From 51c9497e4f90555b45f17d01b0b469f96ebdf27e Mon Sep 17 00:00:00 2001 From: Brett Cannon Date: Fri, 1 Sep 2023 16:39:10 -0700 Subject: [PATCH 3/3] Tweak comments on parameterized tests --- tests/test_tags.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/test_tags.py b/tests/test_tags.py index f8963906..c9e921e1 100644 --- a/tests/test_tags.py +++ b/tests/test_tags.py @@ -1352,12 +1352,12 @@ def teardown_method(self): @pytest.mark.parametrize( "maxsize, sizeof_voidp, expected", [ - # CPython, PyPy, pyston 64bit + # 64-bit (9223372036854775807, 8, False), - # GraalPy, IronPython, Jython 64bit - (2147483647, 8, False), - # CPython, PyPy, IronPython, Jython, pyodide 32bit + # 32-bit (2147483647, 4, True), + # 64-bit w/ 32-bit sys.maxsize: GraalPy, IronPython, Jython + (2147483647, 8, False), ], ) def test_32bit_interpreter(self, maxsize, sizeof_voidp, expected, monkeypatch):