From 30eeb7a53cd7aa24cd0ff8e7b9f3c10f6d060572 Mon Sep 17 00:00:00 2001 From: Hong Xu Date: Wed, 13 Nov 2019 23:14:03 -0800 Subject: [PATCH 01/11] 32-bit Linux running on 64-bit ARM arch should have platform "linux_armv7l". Currently on a 32-bit OS that runs on a 64-bit ARM CPU (ARM-v8, aarch64), _linux_platforms returns the incorrect string. This commit fixes this issue by following the solution similar to that of the x86_64/x86 pair. --- packaging/tags.py | 7 +++++-- tests/test_tags.py | 20 ++++++++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/packaging/tags.py b/packaging/tags.py index 60a69d8f..3c5e11a5 100644 --- a/packaging/tags.py +++ b/packaging/tags.py @@ -636,8 +636,11 @@ def _have_compatible_manylinux_abi(arch): def _linux_platforms(is_32bit=_32_BIT_INTERPRETER): # type: (bool) -> Iterator[str] linux = _normalize_string(distutils.util.get_platform()) - if linux == "linux_x86_64" and is_32bit: - linux = "linux_i686" + if is_32bit: + if linux == "linux_x86_64": + linux = "linux_i686" + elif linux == "linux_aarch64": + linux = "linux_armv7l" manylinux_support = [] _, arch = linux.split("_", 1) if _have_compatible_manylinux_abi(arch): diff --git a/tests/test_tags.py b/tests/test_tags.py index 1c05969f..ba37733a 100644 --- a/tests/test_tags.py +++ b/tests/test_tags.py @@ -37,6 +37,11 @@ def is_x86(): return re.match(r"(i\d86|x86_64)", platform.machine()) is not None +@pytest.fixture +def is_arm(): + return re.match(r"(armv\d|aarch64)", platform.machine()) is not None + + @pytest.fixture def is_64bit_os(): return platform.architecture()[0] == "64bit" @@ -429,6 +434,21 @@ def test_linux_platforms_32bit_on_64bit_os(self, is_64bit_os, is_x86, monkeypatc linux_platform = list(tags._linux_platforms(is_32bit=True))[-1] assert linux_platform == "linux_i686" + def test_linux_platforms_64bit_on_64bit_os_arm(self, is_64bit_os, is_arm, monkeypatch): + if platform.system() != "Linux" or not is_64bit_os or not is_arm: + monkeypatch.setattr(distutils.util, "get_platform", lambda: "linux_aarch64") + monkeypatch.setattr(tags, "_is_manylinux_compatible", lambda *args: False) + linux_platform = tags._linux_platforms(is_32bit=False)[-1] + assert linux_platform == "linux_aarch64" + + + def test_linux_platforms_32bit_on_64bit_os_arm(self, is_64bit_os, is_arm, monkeypatch): + if platform.system() != "Linux" or not is_64bit_os or not is_arm: + monkeypatch.setattr(distutils.util, "get_platform", lambda: "linux_aarch64") + monkeypatch.setattr(tags, "_is_manylinux_compatible", lambda *args: False) + linux_platform = tags._linux_platforms(is_32bit=True)[-1] + assert linux_platform == "linux_armv7l" + def test_linux_platforms_manylinux_unsupported(self, monkeypatch): monkeypatch.setattr(distutils.util, "get_platform", lambda: "linux_x86_64") monkeypatch.setattr(tags, "_is_manylinux_compatible", lambda *args: False) From a99d87f1f4c2d88ab13648527dc22ec1bf18c26b Mon Sep 17 00:00:00 2001 From: Hong Xu Date: Fri, 24 Jan 2020 11:00:30 -0800 Subject: [PATCH 02/11] Update tests/test_tags.py Co-Authored-By: Brett Cannon <54418+brettcannon@users.noreply.github.com> --- tests/test_tags.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_tags.py b/tests/test_tags.py index ba37733a..3673e33e 100644 --- a/tests/test_tags.py +++ b/tests/test_tags.py @@ -438,7 +438,7 @@ def test_linux_platforms_64bit_on_64bit_os_arm(self, is_64bit_os, is_arm, monkey if platform.system() != "Linux" or not is_64bit_os or not is_arm: monkeypatch.setattr(distutils.util, "get_platform", lambda: "linux_aarch64") monkeypatch.setattr(tags, "_is_manylinux_compatible", lambda *args: False) - linux_platform = tags._linux_platforms(is_32bit=False)[-1] + linux_platform = list(tags._linux_platforms(is_32bit=False))[-1] assert linux_platform == "linux_aarch64" From ca81f77ca07a230adc3f3d401e55f3f6b15dcf9d Mon Sep 17 00:00:00 2001 From: Hong Xu Date: Fri, 24 Jan 2020 11:00:42 -0800 Subject: [PATCH 03/11] Update tests/test_tags.py Co-Authored-By: Brett Cannon <54418+brettcannon@users.noreply.github.com> --- tests/test_tags.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_tags.py b/tests/test_tags.py index 3673e33e..ff14128a 100644 --- a/tests/test_tags.py +++ b/tests/test_tags.py @@ -446,7 +446,7 @@ def test_linux_platforms_32bit_on_64bit_os_arm(self, is_64bit_os, is_arm, monkey if platform.system() != "Linux" or not is_64bit_os or not is_arm: monkeypatch.setattr(distutils.util, "get_platform", lambda: "linux_aarch64") monkeypatch.setattr(tags, "_is_manylinux_compatible", lambda *args: False) - linux_platform = tags._linux_platforms(is_32bit=True)[-1] + linux_platform = list(tags._linux_platforms(is_32bit=True))[-1] assert linux_platform == "linux_armv7l" def test_linux_platforms_manylinux_unsupported(self, monkeypatch): From 22b943aaf33de026702d9732751d00a02f9339b5 Mon Sep 17 00:00:00 2001 From: Hong Xu Date: Mon, 27 Jan 2020 17:00:37 -0800 Subject: [PATCH 04/11] Formatting using black --- tests/test_tags.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/tests/test_tags.py b/tests/test_tags.py index ff14128a..505fb5c1 100644 --- a/tests/test_tags.py +++ b/tests/test_tags.py @@ -434,15 +434,18 @@ def test_linux_platforms_32bit_on_64bit_os(self, is_64bit_os, is_x86, monkeypatc linux_platform = list(tags._linux_platforms(is_32bit=True))[-1] assert linux_platform == "linux_i686" - def test_linux_platforms_64bit_on_64bit_os_arm(self, is_64bit_os, is_arm, monkeypatch): + def test_linux_platforms_64bit_on_64bit_os_arm( + self, is_64bit_os, is_arm, monkeypatch + ): if platform.system() != "Linux" or not is_64bit_os or not is_arm: monkeypatch.setattr(distutils.util, "get_platform", lambda: "linux_aarch64") monkeypatch.setattr(tags, "_is_manylinux_compatible", lambda *args: False) linux_platform = list(tags._linux_platforms(is_32bit=False))[-1] assert linux_platform == "linux_aarch64" - - def test_linux_platforms_32bit_on_64bit_os_arm(self, is_64bit_os, is_arm, monkeypatch): + def test_linux_platforms_32bit_on_64bit_os_arm( + self, is_64bit_os, is_arm, monkeypatch + ): if platform.system() != "Linux" or not is_64bit_os or not is_arm: monkeypatch.setattr(distutils.util, "get_platform", lambda: "linux_aarch64") monkeypatch.setattr(tags, "_is_manylinux_compatible", lambda *args: False) From e9a63ddae726fce093964cee52ccbd97c7b9c266 Mon Sep 17 00:00:00 2001 From: Hong Xu Date: Mon, 27 Jan 2020 17:42:51 -0800 Subject: [PATCH 05/11] Correct platform string in the tests --- tests/test_tags.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_tags.py b/tests/test_tags.py index 505fb5c1..a4492a8a 100644 --- a/tests/test_tags.py +++ b/tests/test_tags.py @@ -438,7 +438,7 @@ def test_linux_platforms_64bit_on_64bit_os_arm( self, is_64bit_os, is_arm, monkeypatch ): if platform.system() != "Linux" or not is_64bit_os or not is_arm: - monkeypatch.setattr(distutils.util, "get_platform", lambda: "linux_aarch64") + monkeypatch.setattr(distutils.util, "get_platform", lambda: "linux-aarch64") monkeypatch.setattr(tags, "_is_manylinux_compatible", lambda *args: False) linux_platform = list(tags._linux_platforms(is_32bit=False))[-1] assert linux_platform == "linux_aarch64" @@ -447,7 +447,7 @@ def test_linux_platforms_32bit_on_64bit_os_arm( self, is_64bit_os, is_arm, monkeypatch ): if platform.system() != "Linux" or not is_64bit_os or not is_arm: - monkeypatch.setattr(distutils.util, "get_platform", lambda: "linux_aarch64") + monkeypatch.setattr(distutils.util, "get_platform", lambda: "linux-aarch64") monkeypatch.setattr(tags, "_is_manylinux_compatible", lambda *args: False) linux_platform = list(tags._linux_platforms(is_32bit=True))[-1] assert linux_platform == "linux_armv7l" From 063710c4137e7f4f933b7fd06e0c00a579dbcf47 Mon Sep 17 00:00:00 2001 From: Hong Xu Date: Wed, 29 Jan 2020 07:21:01 -0800 Subject: [PATCH 06/11] Update CHANGELOG.rst --- CHANGELOG.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 58aa51a7..b0974308 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -4,7 +4,8 @@ Changelog *unreleased* ~~~~~~~~~~~~ -No changes yet. +* Fixa bug that on a 32-bit OS that runs on a 64-bit ARM CPU (ARM-v8, + aarch64), _linux_platforms returns the incorrect string. 20.1 - 2020-01-24 ~~~~~~~~~~~~~~~~~~~ From 96f096caaa86e59f27bef30ce3456f46f947d4dc Mon Sep 17 00:00:00 2001 From: Hong Xu Date: Fri, 31 Jan 2020 16:50:04 -0800 Subject: [PATCH 07/11] Update CHANGELOG.rst Co-Authored-By: Brett Cannon <54418+brettcannon@users.noreply.github.com> --- CHANGELOG.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index b0974308..d44cebd9 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -4,7 +4,7 @@ Changelog *unreleased* ~~~~~~~~~~~~ -* Fixa bug that on a 32-bit OS that runs on a 64-bit ARM CPU (ARM-v8, +* Fix a bug that on caused a 32-bit OS that runs on a 64-bit ARM CPU (e.g. ARM-v8, aarch64), _linux_platforms returns the incorrect string. 20.1 - 2020-01-24 From 931b182dc8afd4a21d5f764a7fd43ee06fae9365 Mon Sep 17 00:00:00 2001 From: Hong Xu Date: Fri, 31 Jan 2020 16:51:13 -0800 Subject: [PATCH 08/11] Update CHANGELOG.rst Co-Authored-By: Brett Cannon <54418+brettcannon@users.noreply.github.com> --- CHANGELOG.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index d44cebd9..5d2ecc2f 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -5,7 +5,7 @@ Changelog ~~~~~~~~~~~~ * Fix a bug that on caused a 32-bit OS that runs on a 64-bit ARM CPU (e.g. ARM-v8, - aarch64), _linux_platforms returns the incorrect string. + aarch64), to report the wrong bitness. 20.1 - 2020-01-24 ~~~~~~~~~~~~~~~~~~~ From 76fa89cc230c708b4c2bc1effd1aec2e366c675c Mon Sep 17 00:00:00 2001 From: Hong Xu Date: Fri, 31 Jan 2020 16:51:44 -0800 Subject: [PATCH 09/11] Update CHANGELOG.rst --- CHANGELOG.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 5d2ecc2f..a56d6463 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -4,7 +4,7 @@ Changelog *unreleased* ~~~~~~~~~~~~ -* Fix a bug that on caused a 32-bit OS that runs on a 64-bit ARM CPU (e.g. ARM-v8, +* Fix a bug that caused a 32-bit OS that runs on a 64-bit ARM CPU (e.g. ARM-v8, aarch64), to report the wrong bitness. 20.1 - 2020-01-24 From fd1533e7abcd2c8fa8065dd922c5ebd05896c1c1 Mon Sep 17 00:00:00 2001 From: Hong Xu Date: Sat, 1 Feb 2020 21:20:20 -0800 Subject: [PATCH 10/11] Parametrize the tests --- tests/test_tags.py | 60 ++++++++++++---------------------------------- 1 file changed, 15 insertions(+), 45 deletions(-) diff --git a/tests/test_tags.py b/tests/test_tags.py index a4492a8a..1e44fa90 100644 --- a/tests/test_tags.py +++ b/tests/test_tags.py @@ -32,21 +32,6 @@ def example_tag(): return tags.Tag("py3", "none", "any") -@pytest.fixture -def is_x86(): - return re.match(r"(i\d86|x86_64)", platform.machine()) is not None - - -@pytest.fixture -def is_arm(): - return re.match(r"(armv\d|aarch64)", platform.machine()) is not None - - -@pytest.fixture -def is_64bit_os(): - return platform.architecture()[0] == "64bit" - - @pytest.fixture def manylinux_module(monkeypatch): monkeypatch.setattr(tags, "_have_compatible_glibc", lambda *args: False) @@ -420,37 +405,22 @@ def test_glibc_version_string_none(self, monkeypatch): monkeypatch.setattr(tags, "_glibc_version_string", lambda: None) assert not tags._have_compatible_glibc(2, 4) - def test_linux_platforms_64bit_on_64bit_os(self, is_64bit_os, is_x86, monkeypatch): - if platform.system() != "Linux" or not is_64bit_os or not is_x86: - monkeypatch.setattr(distutils.util, "get_platform", lambda: "linux_x86_64") - monkeypatch.setattr(tags, "_is_manylinux_compatible", lambda *args: False) - linux_platform = list(tags._linux_platforms(is_32bit=False))[-1] - assert linux_platform == "linux_x86_64" - - def test_linux_platforms_32bit_on_64bit_os(self, is_64bit_os, is_x86, monkeypatch): - if platform.system() != "Linux" or not is_64bit_os or not is_x86: - monkeypatch.setattr(distutils.util, "get_platform", lambda: "linux_x86_64") - monkeypatch.setattr(tags, "_is_manylinux_compatible", lambda *args: False) - linux_platform = list(tags._linux_platforms(is_32bit=True))[-1] - assert linux_platform == "linux_i686" - - def test_linux_platforms_64bit_on_64bit_os_arm( - self, is_64bit_os, is_arm, monkeypatch - ): - if platform.system() != "Linux" or not is_64bit_os or not is_arm: - monkeypatch.setattr(distutils.util, "get_platform", lambda: "linux-aarch64") - monkeypatch.setattr(tags, "_is_manylinux_compatible", lambda *args: False) - linux_platform = list(tags._linux_platforms(is_32bit=False))[-1] - assert linux_platform == "linux_aarch64" - - def test_linux_platforms_32bit_on_64bit_os_arm( - self, is_64bit_os, is_arm, monkeypatch + @pytest.mark.parametrize( + "arch,is_32bit,expected", + [ + ("linux-x86_64", False, "linux_x86_64"), + ("linux-x86_64", True, "linux_i686"), + ("linux-aarch64", False, "linux_aarch64"), + ("linux-aarch64", True, "linux_armv7l"), + ], + ) + def test_linux_platforms_32_64bit_on_64bit_os( + self, arch, is_32bit, expected, monkeypatch ): - if platform.system() != "Linux" or not is_64bit_os or not is_arm: - monkeypatch.setattr(distutils.util, "get_platform", lambda: "linux-aarch64") - monkeypatch.setattr(tags, "_is_manylinux_compatible", lambda *args: False) - linux_platform = list(tags._linux_platforms(is_32bit=True))[-1] - assert linux_platform == "linux_armv7l" + monkeypatch.setattr(distutils.util, "get_platform", lambda: arch) + monkeypatch.setattr(tags, "_is_manylinux_compatible", lambda *args: False) + linux_platform = list(tags._linux_platforms(is_32bit=is_32bit))[-1] + assert linux_platform == expected def test_linux_platforms_manylinux_unsupported(self, monkeypatch): monkeypatch.setattr(distutils.util, "get_platform", lambda: "linux_x86_64") From 8af083083cd62d6e68af8717eb414dd4086ec64e Mon Sep 17 00:00:00 2001 From: Brett Cannon <54418+brettcannon@users.noreply.github.com> Date: Wed, 5 Feb 2020 16:41:38 -0800 Subject: [PATCH 11/11] Add back in the is_x86() fixture --- tests/test_tags.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/test_tags.py b/tests/test_tags.py index 3da93b04..82364898 100644 --- a/tests/test_tags.py +++ b/tests/test_tags.py @@ -32,6 +32,11 @@ def example_tag(): return tags.Tag("py3", "none", "any") +@pytest.fixture +def is_x86(): + return re.match(r"(i\d86|x86_64)", platform.machine()) is not None + + @pytest.fixture def manylinux_module(monkeypatch): monkeypatch.setattr(tags, "_have_compatible_glibc", lambda *args: False)