Skip to content

Commit

Permalink
Removed install dependency on setuptools (#483)
Browse files Browse the repository at this point in the history
Also re-added the fallback for `license_paths` on setuptools versions older than 57.
  • Loading branch information
agronholm committed Nov 4, 2022
1 parent 747e1f6 commit 9ec2016
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 5 deletions.
4 changes: 4 additions & 0 deletions 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
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Expand Up @@ -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]
Expand Down
47 changes: 45 additions & 2 deletions src/wheel/bdist_wheel.py
Expand Up @@ -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
Expand All @@ -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"

Expand Down Expand Up @@ -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"""
Expand Down
7 changes: 5 additions & 2 deletions src/wheel/cli/convert.py
Expand Up @@ -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<name>.+?)-(?P<ver>.+?)
Expand Down
11 changes: 11 additions & 0 deletions tests/test_bdist_wheel.py
Expand Up @@ -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",
[
Expand Down

0 comments on commit 9ec2016

Please sign in to comment.