From 00eb2c82483914a40c50999285397141e0576873 Mon Sep 17 00:00:00 2001 From: Tzu-ping Chung Date: Sat, 24 Apr 2021 02:49:54 +0800 Subject: [PATCH] Replace distutils usage with sysconfig (#396) (cherry picked from commit c8008265eac83ebf2c3b3c314a682abd4c101de2) --- packaging/tags.py | 6 ++---- tests/test_tags.py | 33 ++++++++++++++++----------------- 2 files changed, 18 insertions(+), 21 deletions(-) diff --git a/packaging/tags.py b/packaging/tags.py index d637f1b..de4dc91 100644 --- a/packaging/tags.py +++ b/packaging/tags.py @@ -4,8 +4,6 @@ from __future__ import absolute_import -import distutils.util - try: from importlib.machinery import EXTENSION_SUFFIXES except ImportError: # pragma: no cover @@ -781,7 +779,7 @@ def _manylinux_tags(linux, arch): def _linux_platforms(is_32bit=_32_BIT_INTERPRETER): # type: (bool) -> Iterator[str] - linux = _normalize_string(distutils.util.get_platform()) + linux = _normalize_string(sysconfig.get_platform()) if is_32bit: if linux == "linux_x86_64": linux = "linux_i686" @@ -796,7 +794,7 @@ def _linux_platforms(is_32bit=_32_BIT_INTERPRETER): def _generic_platforms(): # type: () -> Iterator[str] - yield _normalize_string(distutils.util.get_platform()) + yield _normalize_string(sysconfig.get_platform()) def _platform_tags(): diff --git a/tests/test_tags.py b/tests/test_tags.py index 6b0e5b6..3537379 100644 --- a/tests/test_tags.py +++ b/tests/test_tags.py @@ -11,7 +11,6 @@ try: import ctypes except ImportError: ctypes = None -import distutils.util import os import platform import re @@ -492,14 +491,14 @@ class TestManylinuxPlatform: def test_linux_platforms_32_64bit_on_64bit_os( self, arch, is_32bit, expected, monkeypatch ): - monkeypatch.setattr(distutils.util, "get_platform", lambda: arch) + monkeypatch.setattr(sysconfig, "get_platform", lambda: arch) monkeypatch.setattr(os, "confstr", lambda x: "glibc 2.20", raising=False) 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") + monkeypatch.setattr(sysconfig, "get_platform", lambda: "linux_x86_64") monkeypatch.setattr(os, "confstr", lambda x: "glibc 2.20", raising=False) monkeypatch.setattr(tags, "_is_manylinux_compatible", lambda *args: False) linux_platform = list(tags._linux_platforms(is_32bit=False)) @@ -509,7 +508,7 @@ class TestManylinuxPlatform: monkeypatch.setattr( tags, "_is_manylinux_compatible", lambda name, *args: name == "manylinux1" ) - monkeypatch.setattr(distutils.util, "get_platform", lambda: "linux_x86_64") + monkeypatch.setattr(sysconfig, "get_platform", lambda: "linux_x86_64") monkeypatch.setattr(platform, "machine", lambda: "x86_64") monkeypatch.setattr(os, "confstr", lambda x: "glibc 2.20", raising=False) platforms = list(tags._linux_platforms(is_32bit=False)) @@ -517,7 +516,7 @@ class TestManylinuxPlatform: assert platforms == ["manylinux1_" + arch, "linux_" + arch] def test_linux_platforms_manylinux2010(self, monkeypatch): - monkeypatch.setattr(distutils.util, "get_platform", lambda: "linux_x86_64") + monkeypatch.setattr(sysconfig, "get_platform", lambda: "linux_x86_64") monkeypatch.setattr(platform, "machine", lambda: "x86_64") monkeypatch.setattr(os, "confstr", lambda x: "glibc 2.12", raising=False) platforms = list(tags._linux_platforms(is_32bit=False)) @@ -538,7 +537,7 @@ class TestManylinuxPlatform: assert platforms == expected def test_linux_platforms_manylinux2014(self, monkeypatch): - monkeypatch.setattr(distutils.util, "get_platform", lambda: "linux_x86_64") + monkeypatch.setattr(sysconfig, "get_platform", lambda: "linux_x86_64") monkeypatch.setattr(platform, "machine", lambda: "x86_64") monkeypatch.setattr(os, "confstr", lambda x: "glibc 2.17", raising=False) platforms = list(tags._linux_platforms(is_32bit=False)) @@ -571,7 +570,7 @@ class TestManylinuxPlatform: "_is_manylinux_compatible", lambda name, *args: name == "manylinux2014", ) - monkeypatch.setattr(distutils.util, "get_platform", lambda: "linux_armv7l") + monkeypatch.setattr(sysconfig, "get_platform", lambda: "linux_armv7l") monkeypatch.setattr( sys, "executable", @@ -583,7 +582,7 @@ class TestManylinuxPlatform: def test_linux_platforms_manylinux2014_i386_abi(self, monkeypatch): monkeypatch.setattr(tags, "_glibc_version_string", lambda: "2.17") - monkeypatch.setattr(distutils.util, "get_platform", lambda: "linux_x86_64") + monkeypatch.setattr(sysconfig, "get_platform", lambda: "linux_x86_64") monkeypatch.setattr( sys, "executable", @@ -615,7 +614,7 @@ class TestManylinuxPlatform: # test for a future glic 3.x version monkeypatch.setattr(tags, "_glibc_version_string", lambda: "3.2") monkeypatch.setattr(tags, "_is_manylinux_compatible", lambda name, *args: True) - monkeypatch.setattr(distutils.util, "get_platform", lambda: "linux_aarch64") + monkeypatch.setattr(sysconfig, "get_platform", lambda: "linux_aarch64") monkeypatch.setattr( sys, "executable", @@ -633,7 +632,7 @@ class TestManylinuxPlatform: monkeypatch.setattr( tags, "_is_manylinux_compatible", lambda name, _: name == "manylinux2014" ) - monkeypatch.setattr(distutils.util, "get_platform", lambda: "linux_armv6l") + monkeypatch.setattr(sysconfig, "get_platform", lambda: "linux_armv6l") monkeypatch.setattr(os, "confstr", lambda x: "glibc 2.20", raising=False) platforms = list(tags._linux_platforms(is_32bit=True)) expected = ["linux_armv6l"] @@ -648,7 +647,7 @@ class TestManylinuxPlatform: ): monkeypatch.setattr(tags, "_is_manylinux_compatible", lambda name, _: False) monkeypatch.setattr( - distutils.util, "get_platform", lambda: "linux_{}".format(machine) + sysconfig, "get_platform", lambda: "linux_{}".format(machine) ) monkeypatch.setattr( sys, @@ -995,7 +994,7 @@ class TestGenericTags: assert not list(tags._generic_abi()) def test_generic_platforms(self): - platform = distutils.util.get_platform().replace("-", "_") + platform = sysconfig.get_platform().replace("-", "_") platform = platform.replace(".", "_") assert list(tags._generic_platforms()) == [platform] @@ -1269,14 +1268,14 @@ class TestSysTags: assert result[-1] == expected def test_linux_platforms_manylinux2014_armv6l(self, monkeypatch, manylinux_module): - monkeypatch.setattr(distutils.util, "get_platform", lambda: "linux_armv6l") + monkeypatch.setattr(sysconfig, "get_platform", lambda: "linux_armv6l") monkeypatch.setattr(os, "confstr", lambda x: "glibc 2.20", raising=False) platforms = list(tags._linux_platforms(is_32bit=True)) expected = ["linux_armv6l"] assert platforms == expected def test_skip_manylinux_2014(self, monkeypatch, manylinux_module): - monkeypatch.setattr(distutils.util, "get_platform", lambda: "linux_ppc64") + monkeypatch.setattr(sysconfig, "get_platform", lambda: "linux_ppc64") monkeypatch.setattr(tags, "_get_glibc_version", lambda: (2, 20)) monkeypatch.setattr( manylinux_module, "manylinux2014_compatible", False, raising=False @@ -1300,7 +1299,7 @@ class TestSysTags: self, monkeypatch, manylinux_module, machine, abi, alt_machine ): monkeypatch.setattr( - distutils.util, "get_platform", lambda: "linux_{}".format(machine) + sysconfig, "get_platform", lambda: "linux_{}".format(machine) ) monkeypatch.setattr( sys, @@ -1326,7 +1325,7 @@ class TestSysTags: monkeypatch.setattr(tags, "_get_glibc_version", lambda: (major, minor)) monkeypatch.setattr( - distutils.util, "get_platform", lambda: "linux_{}".format(machine) + sysconfig, "get_platform", lambda: "linux_{}".format(machine) ) monkeypatch.setattr( manylinux_module, @@ -1349,7 +1348,7 @@ class TestSysTags: return None monkeypatch.setattr(tags, "_get_glibc_version", lambda: (2, 30)) - monkeypatch.setattr(distutils.util, "get_platform", lambda: "linux_x86_64") + monkeypatch.setattr(sysconfig, "get_platform", lambda: "linux_x86_64") monkeypatch.setattr( manylinux_module, "manylinux_compatible",