diff options
| author | Alex Grönholm <alex.gronholm@nextday.fi> | 2021-12-24 21:56:43 +0200 |
|---|---|---|
| committer | Alex Grönholm <alex.gronholm@nextday.fi> | 2021-12-24 21:56:43 +0200 |
| commit | 55dfd587ed6182b8af224906a467dbd3f7ae1433 (patch) | |
| tree | 9f34f543af49e3843019804636524b77fb1d3870 | |
| parent | fdb6eca68c3c1e7258f9be5236f511827289947f (diff) | |
| download | wheel-git-55dfd587ed6182b8af224906a467dbd3f7ae1433.tar.gz | |
Replaced distutils with setuptools
Distutils has been deprecated and will be removed in Python 3.12.
| -rw-r--r-- | docs/news.rst | 1 | ||||
| -rw-r--r-- | setup.cfg | 2 | ||||
| -rw-r--r-- | src/wheel/bdist_wheel.py | 41 | ||||
| -rwxr-xr-x | src/wheel/cli/convert.py | 11 | ||||
| -rw-r--r-- | tests/test_macosx_libfile.py | 22 |
5 files changed, 44 insertions, 33 deletions
diff --git a/docs/news.rst b/docs/news.rst index 8b84045..aa46010 100644 --- a/docs/news.rst +++ b/docs/news.rst @@ -5,6 +5,7 @@ Release Notes - Dropped support for Python < 3.7 - Updated vendored ``packaging`` to 21.3 +- Replaced all uses of ``distutils`` with ``setuptools`` **0.37.1 (2021-12-22)** @@ -31,7 +31,7 @@ package_dir= = src packages = find: python_requires = >=3.7 -setup_requires = setuptools >= 45.2.0 +install_requires = setuptools >= 45.2.0 zip_safe = False [options.packages.find] diff --git a/src/wheel/bdist_wheel.py b/src/wheel/bdist_wheel.py index cdea46d..bf2500c 100644 --- a/src/wheel/bdist_wheel.py +++ b/src/wheel/bdist_wheel.py @@ -4,16 +4,14 @@ Create a wheel (.whl) distribution. A wheel is a built archive format. """ -import distutils import os import re import shutil import stat import sys +import sysconfig import warnings from collections import OrderedDict -from distutils import log as logger -from distutils.core import Command from email.generator import BytesGenerator from glob import iglob from io import BytesIO @@ -22,6 +20,7 @@ from sysconfig import get_config_var from zipfile import ZIP_DEFLATED, ZIP_STORED import pkg_resources +from setuptools import Command from . import __version__ as wheel_version from .macosx_libfile import calculate_macosx_platform_tag @@ -36,20 +35,31 @@ safe_version = pkg_resources.safe_version PY_LIMITED_API_PATTERN = r"cp3\d" +def log(msg, *, error=False): + stream = sys.stderr if error else sys.stdout + try: + print(msg, file=stream, flush=True) + except UnicodeEncodeError: + # emulate backslashreplace error handler + encoding = stream.encoding + msg = msg.encode(encoding, "backslashreplace").decode(encoding) + print(msg, file=stream, flush=True) + + def python_tag(): return f"py{sys.version_info[0]}" def get_platform(archive_root): """Return our platform name 'win32', 'linux_x86_64'""" - # XXX remove distutils dependency - result = distutils.util.get_platform() + result = sysconfig.get_platform() if result.startswith("macosx") and archive_root is not None: result = calculate_macosx_platform_tag(archive_root, result) if result == "linux_x86_64" and sys.maxsize == 2147483647: # pip pull request #3497 result = "linux_i686" - return result + + return result.replace("-", "_") def get_flag(var, fallback, expected=True, warn=True): @@ -237,7 +247,10 @@ class bdist_wheel(Command): wheel = self.distribution.get_option_dict("wheel") if "universal" in wheel: # please don't define this in your global configs - logger.warn("The [wheel] section is deprecated. Use [bdist_wheel] instead.") + log( + "The [wheel] section is deprecated. Use [bdist_wheel] instead.", + error=True, + ) val = wheel["universal"][1].strip() if val.lower() in ("1", "true", "yes"): self.universal = True @@ -352,7 +365,7 @@ class bdist_wheel(Command): basedir_observed, ) - logger.info("installing to %s", self.bdist_dir) + log(f"installing to {self.bdist_dir}") self.run_command("install") @@ -393,7 +406,7 @@ class bdist_wheel(Command): ) if not self.keep_temp: - logger.info("removing %s", self.bdist_dir) + log(f"removing {self.bdist_dir}") if not self.dry_run: rmtree(self.bdist_dir, onerror=remove_readonly) @@ -417,7 +430,7 @@ class bdist_wheel(Command): msg["Tag"] = "-".join((impl, abi, plat)) wheelfile_path = os.path.join(wheelfile_base, "WHEEL") - logger.info("creating %s", wheelfile_path) + log("creating {wheelfile_path}") buffer = BytesIO() BytesGenerator(buffer, maxheaderlen=0).flatten(msg) with open(wheelfile_path, "wb") as f: @@ -452,15 +465,11 @@ class bdist_wheel(Command): for pattern in patterns: for path in iglob(pattern): if path.endswith("~"): - logger.debug( - 'ignoring license file "%s" as it looks like a backup', path - ) + log(f'ignoring license file "{path}" as it looks like a backup') continue if path not in files and os.path.isfile(path): - logger.info( - 'adding license file "%s" (matched pattern "%s")', path, pattern - ) + log(f'adding license file "{path}" (matched pattern "{pattern}")') files.add(path) return files diff --git a/src/wheel/cli/convert.py b/src/wheel/cli/convert.py index b2f685f..a4bec18 100755 --- a/src/wheel/cli/convert.py +++ b/src/wheel/cli/convert.py @@ -3,9 +3,10 @@ import re import shutil import tempfile import zipfile -from distutils import dist from glob import iglob +from setuptools.dist import Distribution + from ..bdist_wheel import bdist_wheel from ..wheelfile import WheelFile from . import WheelError, require_pkgresources @@ -68,9 +69,9 @@ def egg2wheel(egg_path, dest_dir): root_is_purelib = egg_info["arch"] is None if root_is_purelib: - bw = bdist_wheel(dist.Distribution()) + bw = bdist_wheel(Distribution()) else: - bw = _bdist_wheel_tag(dist.Distribution()) + bw = _bdist_wheel_tag(Distribution()) bw.root_is_pure = root_is_purelib bw.python_tag = pyver @@ -227,9 +228,9 @@ def wininst2wheel(path, dest_dir): pyver = pyver.replace("py", "cp") wheel_name = "-".join((dist_info, pyver, abi, arch)) if root_is_purelib: - bw = bdist_wheel(dist.Distribution()) + bw = bdist_wheel(Distribution()) else: - bw = _bdist_wheel_tag(dist.Distribution()) + bw = _bdist_wheel_tag(Distribution()) bw.root_is_pure = root_is_purelib bw.python_tag = pyver diff --git a/tests/test_macosx_libfile.py b/tests/test_macosx_libfile.py index 640cc17..6e3bfd4 100644 --- a/tests/test_macosx_libfile.py +++ b/tests/test_macosx_libfile.py @@ -1,6 +1,6 @@ -import distutils.util import os import sys +import sysconfig from wheel.bdist_wheel import get_platform from wheel.macosx_libfile import extract_macosx_min_system_version @@ -50,7 +50,7 @@ class TestGetPlatformMacosx: dirname = os.path.dirname(__file__) dylib_dir = os.path.join(dirname, "testdata", "macosx_minimal_system_version") monkeypatch.setattr( - distutils.util, "get_platform", return_factory("macosx-11.0-x86_64") + sysconfig, "get_platform", return_factory("macosx-11.0-x86_64") ) assert get_platform(dylib_dir) == "macosx_11_0_x86_64" @@ -58,7 +58,7 @@ class TestGetPlatformMacosx: dirname = os.path.dirname(__file__) dylib_dir = os.path.join(dirname, "testdata", "macosx_minimal_system_version") monkeypatch.setattr( - distutils.util, "get_platform", return_factory("macosx-10.9-x86_64") + sysconfig, "get_platform", return_factory("macosx-10.9-x86_64") ) assert get_platform(dylib_dir) == "macosx_11_0_x86_64" captured = capsys.readouterr() @@ -70,7 +70,7 @@ class TestGetPlatformMacosx: dirname = os.path.dirname(__file__) dylib_dir = os.path.join(dirname, "testdata", "macosx_minimal_system_version") monkeypatch.setattr( - distutils.util, "get_platform", return_factory("macosx-10.9-x86_64") + sysconfig, "get_platform", return_factory("macosx-10.9-x86_64") ) monkeypatch.setattr( os, @@ -93,7 +93,7 @@ class TestGetPlatformMacosx: dirname = os.path.dirname(__file__) dylib_dir = os.path.join(dirname, "testdata", "macosx_minimal_system_version") monkeypatch.setattr( - distutils.util, "get_platform", return_factory("macosx-10.9-x86_64") + sysconfig, "get_platform", return_factory("macosx-10.9-x86_64") ) monkeypatch.setenv("MACOSX_DEPLOYMENT_TARGET", "10.8") monkeypatch.setattr( @@ -113,7 +113,7 @@ class TestGetPlatformMacosx: dirname = os.path.dirname(__file__) dylib_dir = os.path.join(dirname, "testdata", "macosx_minimal_system_version") monkeypatch.setattr( - distutils.util, "get_platform", return_factory("macosx-10.9-x86_64") + sysconfig, "get_platform", return_factory("macosx-10.9-x86_64") ) monkeypatch.setattr( os, @@ -132,7 +132,7 @@ class TestGetPlatformMacosx: dirname = os.path.dirname(__file__) dylib_dir = os.path.join(dirname, "testdata", "macosx_minimal_system_version") monkeypatch.setattr( - distutils.util, "get_platform", return_factory("macosx-10.9-x86_64") + sysconfig, "get_platform", return_factory("macosx-10.9-x86_64") ) monkeypatch.setattr( os, @@ -163,7 +163,7 @@ class TestGetPlatformMacosx: dirname = os.path.dirname(__file__) dylib_dir = os.path.join(dirname, "testdata", "macosx_minimal_system_version") monkeypatch.setattr( - distutils.util, "get_platform", return_factory("macosx-10.9-x86_64") + sysconfig, "get_platform", return_factory("macosx-10.9-x86_64") ) monkeypatch.setenv("MACOSX_DEPLOYMENT_TARGET", "10.8") monkeypatch.setattr( @@ -184,7 +184,7 @@ class TestGetPlatformMacosx: dirname = os.path.dirname(__file__) dylib_dir = os.path.join(dirname, "testdata", "macosx_minimal_system_version") monkeypatch.setattr( - distutils.util, "get_platform", return_factory("macosx-10.9-x86_64") + sysconfig, "get_platform", return_factory("macosx-10.9-x86_64") ) monkeypatch.setenv("MACOSX_DEPLOYMENT_TARGET", "11") monkeypatch.setattr( @@ -200,7 +200,7 @@ class TestGetPlatformMacosx: dirname = os.path.dirname(__file__) dylib_dir = os.path.join(dirname, "testdata", "macosx_minimal_system_version") monkeypatch.setattr( - distutils.util, "get_platform", return_factory("macosx-11-x86_64") + sysconfig, "get_platform", return_factory("macosx-11-x86_64") ) monkeypatch.setattr( os, @@ -213,6 +213,6 @@ class TestGetPlatformMacosx: def test_get_platform_linux(monkeypatch): - monkeypatch.setattr(distutils.util, "get_platform", return_factory("linux_x86_64")) + monkeypatch.setattr(sysconfig, "get_platform", return_factory("linux_x86_64")) monkeypatch.setattr(sys, "maxsize", 2147483647) assert get_platform(None) == "linux_i686" |
