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: diff --git a/tests/test_tags.py b/tests/test_tags.py index 870ef4ec..c9e921e1 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", + [ + # 64-bit + (9223372036854775807, 8, False), + # 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): + 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