Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed install dependency on setuptools #483

Merged
merged 4 commits into from Nov 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 sysconfig import get_config_var
Expand All @@ -32,6 +33,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 @@ -431,8 +435,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 @@ -82,6 +82,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