diff --git a/docs/news.rst b/docs/news.rst index 98eb19d2..a64b5f12 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 diff --git a/setup.cfg b/setup.cfg index f83f17a2..b4a7b147 100644 --- a/setup.cfg +++ b/setup.cfg @@ -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 3a82caa8..4754fd11 100644 --- a/src/wheel/bdist_wheel.py +++ b/src/wheel/bdist_wheel.py @@ -15,6 +15,7 @@ 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 @@ 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 @@ def _ensure_relative(self, path): @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 0ca66f33..1287059d 100755 --- a/src/wheel/cli/convert.py +++ b/src/wheel/cli/convert.py @@ -7,12 +7,15 @@ 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.+?)-(?P.+?) diff --git a/tests/test_bdist_wheel.py b/tests/test_bdist_wheel.py index d54cee77..531d9e6f 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", [