diff options
| author | Alex Grönholm <alex.gronholm@nextday.fi> | 2022-11-04 11:05:00 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-11-04 11:05:00 +0200 |
| commit | 9ec201660fa07ee0714edd17c979a7039ea852a4 (patch) | |
| tree | 3217054035ebccb33cc0990ea12b8c561f50eb51 | |
| parent | 747e1f6090547abcf65108c5a229cbe21a64a2ae (diff) | |
| download | wheel-git-9ec201660fa07ee0714edd17c979a7039ea852a4.tar.gz | |
Removed install dependency on setuptools (#483)
Also re-added the fallback for `license_paths` on setuptools versions older than 57.
| -rw-r--r-- | docs/news.rst | 4 | ||||
| -rw-r--r-- | setup.cfg | 2 | ||||
| -rw-r--r-- | src/wheel/bdist_wheel.py | 47 | ||||
| -rwxr-xr-x | src/wheel/cli/convert.py | 7 | ||||
| -rw-r--r-- | tests/test_bdist_wheel.py | 11 |
5 files changed, 66 insertions, 5 deletions
diff --git a/docs/news.rst b/docs/news.rst index 98eb19d..a64b5f1 100644 --- a/docs/news.rst +++ b/docs/news.rst @@ -1,6 +1,10 @@ Release Notes ============= +**UNRELEASED** + +- Removed install dependency on setuptools + **0.38.0 (2022-10-21)** - Dropped support for Python < 3.7 @@ -32,7 +32,7 @@ package_dir= = src packages = find: python_requires = >=3.7 -install_requires = setuptools >= 57.0.0 +setup_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 3a82caa..4754fd1 100644 --- a/src/wheel/bdist_wheel.py +++ b/src/wheel/bdist_wheel.py @@ -15,6 +15,7 @@ import sysconfig import warnings from collections import OrderedDict from email.generator import BytesGenerator, Generator +from glob import iglob from io import BytesIO from shutil import rmtree from zipfile import ZIP_DEFLATED, ZIP_STORED @@ -31,6 +32,9 @@ from .wheelfile import WheelFile safe_name = pkg_resources.safe_name safe_version = pkg_resources.safe_version +setuptools_major_version = int( + pkg_resources.get_distribution("setuptools").version.split(".")[0] +) PY_LIMITED_API_PATTERN = r"cp3\d" @@ -430,8 +434,47 @@ class bdist_wheel(Command): @property def license_paths(self): - metadata = self.distribution.metadata - return sorted(metadata.license_files or []) + if setuptools_major_version >= 57: + # Setuptools has resolved any patterns to actual file names + return self.distribution.metadata.license_files or () + + files = set() + metadata = self.distribution.get_option_dict("metadata") + if setuptools_major_version >= 42: + # Setuptools recognizes the license_files option but does not do globbing + patterns = self.distribution.metadata.license_files + else: + # Prior to those, wheel is entirely responsible for handling license files + if "license_files" in metadata: + patterns = metadata["license_files"][1].split() + else: + patterns = () + + if "license_file" in metadata: + warnings.warn( + 'The "license_file" option is deprecated. Use "license_files" instead.', + DeprecationWarning, + ) + files.add(metadata["license_file"][1]) + + if not files and not patterns and not isinstance(patterns, list): + patterns = ("LICEN[CS]E*", "COPYING*", "NOTICE*", "AUTHORS*") + + for pattern in patterns: + for path in iglob(pattern): + if path.endswith("~"): + log.debug( + f'ignoring license file "{path}" as it looks like a backup' + ) + continue + + if path not in files and os.path.isfile(path): + log.info( + f'adding license file "{path}" (matched pattern "{pattern}")' + ) + files.add(path) + + return files def egg2dist(self, egginfo_path, distinfo_path): """Convert an .egg-info directory into a .dist-info directory""" diff --git a/src/wheel/cli/convert.py b/src/wheel/cli/convert.py index 0ca66f3..1287059 100755 --- a/src/wheel/cli/convert.py +++ b/src/wheel/cli/convert.py @@ -7,12 +7,15 @@ import tempfile import zipfile from glob import iglob -from setuptools.dist import Distribution - from ..bdist_wheel import bdist_wheel from ..wheelfile import WheelFile from . import WheelError +try: + from setuptools import Distribution +except ImportError: + from distutils.dist import Distribution + egg_info_re = re.compile( r""" (?P<name>.+?)-(?P<ver>.+?) diff --git a/tests/test_bdist_wheel.py b/tests/test_bdist_wheel.py index d54cee7..531d9e6 100644 --- a/tests/test_bdist_wheel.py +++ b/tests/test_bdist_wheel.py @@ -84,6 +84,17 @@ def test_licenses_default(dummy_dist, monkeypatch, tmpdir): assert set(wf.namelist()) == DEFAULT_FILES | license_files +def test_licenses_deprecated(dummy_dist, monkeypatch, tmpdir): + dummy_dist.join("setup.cfg").write("[metadata]\nlicense_file=licenses/DUMMYFILE") + monkeypatch.chdir(dummy_dist) + subprocess.check_call( + [sys.executable, "setup.py", "bdist_wheel", "-b", str(tmpdir), "--universal"] + ) + with WheelFile("dist/dummy_dist-1.0-py2.py3-none-any.whl") as wf: + license_files = {"dummy_dist-1.0.dist-info/DUMMYFILE"} + assert set(wf.namelist()) == DEFAULT_FILES | license_files + + @pytest.mark.parametrize( "config_file, config", [ |
