From a785aff9ddfb4257fb44778789d4b4f82ea1d544 Mon Sep 17 00:00:00 2001 From: Lawrence D'Anna Date: Thu, 9 Jul 2020 15:46:30 -0700 Subject: [PATCH 1/9] add support for macos 11., arm64, universal2 --- packaging/tags.py | 19 +++++++++++++++++-- tests/test_tags.py | 27 ++++++++++++++++++++++++--- 2 files changed, 41 insertions(+), 5 deletions(-) diff --git a/packaging/tags.py b/packaging/tags.py index 289ed5c1..ad48428c 100644 --- a/packaging/tags.py +++ b/packaging/tags.py @@ -389,7 +389,7 @@ def _mac_binary_formats(version, cpu_arch): if cpu_arch == "x86_64": if version < (10, 4): return [] - formats.extend(["intel", "fat64", "fat32"]) + formats.extend(["intel", "fat64", "fat32", "universal2"]) elif cpu_arch == "i386": if version < (10, 4): @@ -407,7 +407,12 @@ def _mac_binary_formats(version, cpu_arch): return [] formats.extend(["fat32", "fat"]) - formats.append("universal") + elif cpu_arch == "arm64": + formats.append("universal2") + + if cpu_arch != "arm64": + formats.append("universal") + return formats @@ -439,6 +444,16 @@ def mac_platforms(version=None, arch=None): minor=compat_version[1], binary_format=binary_format, ) + if version >= (11, 0) and arch == "x86_64": + for minor_version in range(15, 3, -1): + compat_version = 10, minor_version + binary_formats = _mac_binary_formats(compat_version, arch) + for binary_format in binary_formats: + yield "macosx_{major}_{minor}_{binary_format}".format( + major=compat_version[0], + minor=compat_version[1], + binary_format=binary_format, + ) # From PEP 513, PEP 600 diff --git a/tests/test_tags.py b/tests/test_tags.py index dbffa9b4..913c97b7 100644 --- a/tests/test_tags.py +++ b/tests/test_tags.py @@ -225,8 +225,16 @@ def test_architectures(self, arch, is_32bit, expected): @pytest.mark.parametrize( "version,arch,expected", [ - ((10, 17), "x86_64", ["x86_64", "intel", "fat64", "fat32", "universal"]), - ((10, 4), "x86_64", ["x86_64", "intel", "fat64", "fat32", "universal"]), + ( + (10, 17), + "x86_64", + ["x86_64", "intel", "fat64", "fat32", "universal2", "universal"], + ), + ( + (10, 4), + "x86_64", + ["x86_64", "intel", "fat64", "fat32", "universal2", "universal"], + ), ((10, 3), "x86_64", []), ((10, 17), "i386", ["i386", "intel", "fat32", "fat", "universal"]), ((10, 4), "i386", ["i386", "intel", "fat32", "fat", "universal"]), @@ -271,18 +279,31 @@ def test_mac_platforms(self): "macosx_10_5_intel", "macosx_10_5_fat64", "macosx_10_5_fat32", + "macosx_10_5_universal2", "macosx_10_5_universal", "macosx_10_4_x86_64", "macosx_10_4_intel", "macosx_10_4_fat64", "macosx_10_4_fat32", + "macosx_10_4_universal2", "macosx_10_4_universal", ] - assert len(list(tags.mac_platforms((10, 17), "x86_64"))) == 14 * 5 + assert len(list(tags.mac_platforms((10, 17), "x86_64"))) == 14 * 6 assert not list(tags.mac_platforms((10, 0), "x86_64")) + def test_macos_11(self): + platforms = list(tags.mac_platforms((11, 0), "x86_64")) + assert "macosx_10_15_x86_64" in platforms + assert "macosx_10_4_x86_64" in platforms + assert "macosx_10_3_x86_64" not in platforms + + platforms = list(tags.mac_platforms((11, 0), "arm64")) + assert "macosx_10_15_x86_64" not in platforms + assert "macosx_10_4_x86_64" not in platforms + assert "macosx_10_3_x86_64" not in platforms + class TestManylinuxPlatform: def teardown_method(self): From af377eae14c1d98c3313b3a3fe08b02cee3e46ee Mon Sep 17 00:00:00 2001 From: Lawrence D'Anna <64555057+lawrence-danna-apple@users.noreply.github.com> Date: Mon, 26 Oct 2020 12:55:00 -0700 Subject: [PATCH 2/9] Prevent appending "universal" for unknown arch Co-authored-by: Matthieu Darbois --- packaging/tags.py | 2 +- tests/test_tags.py | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/packaging/tags.py b/packaging/tags.py index ad48428c..af34b4f1 100644 --- a/packaging/tags.py +++ b/packaging/tags.py @@ -410,7 +410,7 @@ def _mac_binary_formats(version, cpu_arch): elif cpu_arch == "arm64": formats.append("universal2") - if cpu_arch != "arm64": + if cpu_arch in {"x86_64", "i386", "ppc64", "ppc"}: formats.append("universal") return formats diff --git a/tests/test_tags.py b/tests/test_tags.py index 913c97b7..5b2458ed 100644 --- a/tests/test_tags.py +++ b/tests/test_tags.py @@ -247,7 +247,13 @@ def test_architectures(self, arch, is_32bit, expected): ((10, 7), "ppc", []), ((10, 6), "ppc", ["ppc", "fat32", "fat", "universal"]), ((10, 0), "ppc", ["ppc", "fat32", "fat", "universal"]), - ((11, 0), "riscv", ["riscv", "universal"]), + ((11, 0), "riscv", ["riscv"]), + ( + (11, 0), + "x86_64", + ["x86_64", "intel", "fat64", "fat32", "universal2", "universal"], + ), + ((11, 0), "arm64", ["arm64", "universal2"]), ], ) def test_binary_formats(self, version, arch, expected): From 194973be4e4ea647ca3c7ef8aa820b31a905d656 Mon Sep 17 00:00:00 2001 From: Lawrence D'Anna Date: Thu, 12 Nov 2020 16:54:53 -0800 Subject: [PATCH 3/9] add tests, fix behavior for versions after 11.0 see comments for explanation --- packaging/tags.py | 37 +++++++++++++++++++++++++++---------- tests/test_tags.py | 40 ++++++++++++++++++++++++++++++++++++---- 2 files changed, 63 insertions(+), 14 deletions(-) diff --git a/packaging/tags.py b/packaging/tags.py index af34b4f1..644ef382 100644 --- a/packaging/tags.py +++ b/packaging/tags.py @@ -435,17 +435,34 @@ def mac_platforms(version=None, arch=None): arch = _mac_arch(cpu_arch) else: arch = arch - for minor_version in range(version[1], -1, -1): - compat_version = version[0], minor_version - binary_formats = _mac_binary_formats(compat_version, arch) - for binary_format in binary_formats: - yield "macosx_{major}_{minor}_{binary_format}".format( - major=compat_version[0], - minor=compat_version[1], - binary_format=binary_format, - ) + + if (10, 0) <= version and version < (11, 0): + # Prior to Mac OS 11, each yearly release of Mac OS bumped the + # "minor" version number. The major version was always 10. + for minor_version in range(version[1], -1, -1): + compat_version = 10, minor_version + binary_formats = _mac_binary_formats(compat_version, arch) + for binary_format in binary_formats: + yield "macosx_{major}_{minor}_{binary_format}".format( + major=10, minor=minor_version, binary_format=binary_format + ) + + if version >= (11, 0): + # Starting with Mac OS 11, each yearly release bumps the major version + # number. The minor versions are now the midyear updates. + for major_version in range(version[0], 10, -1): + compat_version = major_version, 0 + binary_formats = _mac_binary_formats(compat_version, arch) + for binary_format in binary_formats: + yield "macosx_{major}_{minor}_{binary_format}".format( + major=major_version, minor=0, binary_format=binary_format + ) + if version >= (11, 0) and arch == "x86_64": - for minor_version in range(15, 3, -1): + # Mac OS 11 on x86_64 is compatible with binaries from previous releases. + # Arm64 support was introduced in 11.0, so no arm binaries from previous + # releases exist. + for minor_version in range(16, 3, -1): compat_version = 10, minor_version binary_formats = _mac_binary_formats(compat_version, arch) for binary_format in binary_formats: diff --git a/tests/test_tags.py b/tests/test_tags.py index 5b2458ed..67c0b4a7 100644 --- a/tests/test_tags.py +++ b/tests/test_tags.py @@ -299,16 +299,48 @@ def test_mac_platforms(self): assert not list(tags.mac_platforms((10, 0), "x86_64")) - def test_macos_11(self): - platforms = list(tags.mac_platforms((11, 0), "x86_64")) + def _test_macos_11(self, major, minor): + platforms = list(tags.mac_platforms((major, minor), "x86_64")) + assert "macosx_11_0_arm64" not in platforms + assert "macosx_11_0_x86_64" in platforms + assert "macosx_11_3_x86_64" not in platforms + assert "macosx_11_0_universal" in platforms + assert "macosx_11_0_universal2" in platforms + # Mac OS "10.16" is the version number that binaries compiled against an old + # (pre 11.0) SDK will see. It can also be enabled explicitly for a process + # with the environment variable SYSTEM_VERSION_COMPAT=1 + assert "macosx_10_16_x86_64" in platforms assert "macosx_10_15_x86_64" in platforms assert "macosx_10_4_x86_64" in platforms assert "macosx_10_3_x86_64" not in platforms - - platforms = list(tags.mac_platforms((11, 0), "arm64")) + if major >= 12: + assert "macosx_12_0_x86_64" in platforms + assert "macosx_12_0_universal" in platforms + assert "macosx_12_0_universal2" in platforms + + platforms = list(tags.mac_platforms((major, minor), "arm64")) + assert "macosx_11_0_arm64" in platforms + assert "macosx_11_3_arm64" not in platforms + assert "macosx_11_0_universal" not in platforms + assert "macosx_11_0_universal2" in platforms assert "macosx_10_15_x86_64" not in platforms assert "macosx_10_4_x86_64" not in platforms assert "macosx_10_3_x86_64" not in platforms + if major >= 12: + assert "macosx_12_0_arm64" in platforms + assert "macosx_12_0_universal2" in platforms + + def test_macos_11(self): + self._test_macos_11(11, 0) + + def test_macos_11_3(self): + self._test_macos_11(11, 3) + + def test_macos_12(self): + self._test_macos_11(12, 0) + + def test_macos_12_3(self): + self._test_macos_11(12, 3) class TestManylinuxPlatform: From caad9e613d72f72fdd79a46c3151f789c857798a Mon Sep 17 00:00:00 2001 From: Lawrence D'Anna <64555057+lawrence-danna-apple@users.noreply.github.com> Date: Mon, 23 Nov 2020 19:22:15 -0800 Subject: [PATCH 4/9] spelling Co-authored-by: Brett Cannon --- packaging/tags.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/tags.py b/packaging/tags.py index 644ef382..c72c0c10 100644 --- a/packaging/tags.py +++ b/packaging/tags.py @@ -460,7 +460,7 @@ def mac_platforms(version=None, arch=None): if version >= (11, 0) and arch == "x86_64": # Mac OS 11 on x86_64 is compatible with binaries from previous releases. - # Arm64 support was introduced in 11.0, so no arm binaries from previous + # Arm64 support was introduced in 11.0, so no Arm binaries from previous # releases exist. for minor_version in range(16, 3, -1): compat_version = 10, minor_version From df348960d4db36301f916b3587ff8cf6e02ba36b Mon Sep 17 00:00:00 2001 From: Lawrence D'Anna <64555057+lawrence-danna-apple@users.noreply.github.com> Date: Mon, 23 Nov 2020 19:27:23 -0800 Subject: [PATCH 5/9] use pytest.mark.parameterize Co-authored-by: Brett Cannon --- tests/test_tags.py | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/tests/test_tags.py b/tests/test_tags.py index df071902..b0eb5b20 100644 --- a/tests/test_tags.py +++ b/tests/test_tags.py @@ -299,7 +299,8 @@ def test_mac_platforms(self): assert not list(tags.mac_platforms((10, 0), "x86_64")) - def _test_macos_11(self, major, minor): + @pytest.mark.parametrize("major,minor", [(11, 0), (11, 3), (12, 0), (12, 3)]) + def test_macos_11(self, major, minor): platforms = list(tags.mac_platforms((major, minor), "x86_64")) assert "macosx_11_0_arm64" not in platforms assert "macosx_11_0_x86_64" in platforms @@ -330,18 +331,6 @@ def _test_macos_11(self, major, minor): assert "macosx_12_0_arm64" in platforms assert "macosx_12_0_universal2" in platforms - def test_macos_11(self): - self._test_macos_11(11, 0) - - def test_macos_11_3(self): - self._test_macos_11(11, 3) - - def test_macos_12(self): - self._test_macos_11(12, 0) - - def test_macos_12_3(self): - self._test_macos_11(12, 3) - class TestManylinuxPlatform: def teardown_method(self): From b92cf9a859a676c43df3ea8dccff26b52e61c4dc Mon Sep 17 00:00:00 2001 From: Lawrence D'Anna <64555057+lawrence-danna-apple@users.noreply.github.com> Date: Mon, 23 Nov 2020 19:31:32 -0800 Subject: [PATCH 6/9] comment Co-authored-by: Brett Cannon --- 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 b0eb5b20..3de2722b 100644 --- a/tests/test_tags.py +++ b/tests/test_tags.py @@ -309,7 +309,7 @@ def test_macos_11(self, major, minor): assert "macosx_11_0_universal2" in platforms # Mac OS "10.16" is the version number that binaries compiled against an old # (pre 11.0) SDK will see. It can also be enabled explicitly for a process - # with the environment variable SYSTEM_VERSION_COMPAT=1 + # with the environment variable SYSTEM_VERSION_COMPAT=1. assert "macosx_10_16_x86_64" in platforms assert "macosx_10_15_x86_64" in platforms assert "macosx_10_4_x86_64" in platforms From 68f9dc39fefb894db429933173a8fcd99327bca8 Mon Sep 17 00:00:00 2001 From: Lawrence D'Anna <64555057+lawrence-danna-apple@users.noreply.github.com> Date: Mon, 23 Nov 2020 19:37:25 -0800 Subject: [PATCH 7/9] refactor _mac_binary_formats Co-authored-by: Brett Cannon --- packaging/tags.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packaging/tags.py b/packaging/tags.py index c72c0c10..842447d8 100644 --- a/packaging/tags.py +++ b/packaging/tags.py @@ -389,7 +389,7 @@ def _mac_binary_formats(version, cpu_arch): if cpu_arch == "x86_64": if version < (10, 4): return [] - formats.extend(["intel", "fat64", "fat32", "universal2"]) + formats.extend(["intel", "fat64", "fat32"]) elif cpu_arch == "i386": if version < (10, 4): @@ -407,7 +407,7 @@ def _mac_binary_formats(version, cpu_arch): return [] formats.extend(["fat32", "fat"]) - elif cpu_arch == "arm64": + if cpu_arch in {"arm64", "x86_64"}: formats.append("universal2") if cpu_arch in {"x86_64", "i386", "ppc64", "ppc"}: From 0e0921ba165dced97d29810138a1008854d0a7fb Mon Sep 17 00:00:00 2001 From: Lawrence D'Anna Date: Mon, 23 Nov 2020 19:43:44 -0800 Subject: [PATCH 8/9] add some test cases --- tests/test_tags.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/test_tags.py b/tests/test_tags.py index 3de2722b..34b80ed8 100644 --- a/tests/test_tags.py +++ b/tests/test_tags.py @@ -254,6 +254,8 @@ def test_architectures(self, arch, is_32bit, expected): ["x86_64", "intel", "fat64", "fat32", "universal2", "universal"], ), ((11, 0), "arm64", ["arm64", "universal2"]), + ((11, 1), "arm64", ["arm64", "universal2"]), + ((12, 0), "arm64", ["arm64", "universal2"]), ], ) def test_binary_formats(self, version, arch, expected): From 48e8f1cc1595fd79dfd3a8f0fc74bb3cf77a99a3 Mon Sep 17 00:00:00 2001 From: Lawrence D'Anna <64555057+lawrence-danna-apple@users.noreply.github.com> Date: Mon, 23 Nov 2020 19:46:45 -0800 Subject: [PATCH 9/9] Since we know that 10.15 is the last version there's no need to test beyond it. Co-authored-by: Brett Cannon --- 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 34b80ed8..68b109a8 100644 --- a/tests/test_tags.py +++ b/tests/test_tags.py @@ -226,7 +226,7 @@ def test_architectures(self, arch, is_32bit, expected): "version,arch,expected", [ ( - (10, 17), + (10, 15), "x86_64", ["x86_64", "intel", "fat64", "fat32", "universal2", "universal"], ), @@ -236,14 +236,14 @@ def test_architectures(self, arch, is_32bit, expected): ["x86_64", "intel", "fat64", "fat32", "universal2", "universal"], ), ((10, 3), "x86_64", []), - ((10, 17), "i386", ["i386", "intel", "fat32", "fat", "universal"]), + ((10, 15), "i386", ["i386", "intel", "fat32", "fat", "universal"]), ((10, 4), "i386", ["i386", "intel", "fat32", "fat", "universal"]), ((10, 3), "i386", []), - ((10, 17), "ppc64", []), + ((10, 15), "ppc64", []), ((10, 6), "ppc64", []), ((10, 5), "ppc64", ["ppc64", "fat64", "universal"]), ((10, 3), "ppc64", []), - ((10, 17), "ppc", []), + ((10, 15), "ppc", []), ((10, 7), "ppc", []), ((10, 6), "ppc", ["ppc", "fat32", "fat", "universal"]), ((10, 0), "ppc", ["ppc", "fat32", "fat", "universal"]),