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
Add support for license_files
specified in setup.py
#466
Changes from 12 commits
16a4997
c6fd92f
999fb16
bef75a5
d6cb528
5ac2aaa
a411503
acc2173
8055d1c
9fb0b76
819ed28
48fe0d6
8f6b817
81c0bf6
67d20a4
7545b8a
da30500
1682602
5b09d96
16c90f4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,6 @@ | |
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 | ||
|
@@ -432,38 +431,20 @@ def _ensure_relative(self, path): | |
|
||
@property | ||
def license_paths(self): | ||
metadata = self.distribution.get_option_dict("metadata") | ||
metadata = self.distribution.metadata | ||
files = set() | ||
patterns = sorted( | ||
{option for option in metadata.get("license_files", ("", ""))[1].split()} | ||
) | ||
|
||
if "license_file" in metadata: | ||
license_file = getattr(metadata, "license_file", None) | ||
if license_file: | ||
warnings.warn( | ||
'The "license_file" option is deprecated. Use ' | ||
'"license_files" instead.', | ||
DeprecationWarning, | ||
) | ||
files.add(metadata["license_file"][1]) | ||
|
||
if "license_file" not in metadata and "license_files" not in metadata: | ||
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 ' f"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 | ||
files.add(license_file) | ||
|
||
license_files = getattr(metadata, "license_files", None) or [] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is the attribute entirely absent if the option hasn't been provided? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe the attribute is always present if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, so I will remove the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done in 7545b8a. |
||
return sorted({*files, *license_files}) | ||
|
||
def egg2dist(self, egginfo_path, distinfo_path): | ||
"""Convert an .egg-info directory into a .dist-info directory""" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this code path ever triggered on any version of setuptools?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, the user can specify
license_file
instead oflicense_files
(it will already result in a warning from setuptools).I can think about a unit test to add here... (I haven't done that before because the code path was basically inherited from the existing implementation).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm asking because I looked and did not find this attribute on 45.2.0 or 57.0.0. So it would be nice to check if this gets triggered at all or if setuptools just lumps it into
license_files
on its own.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can see here that the
metadata
object has the attribute in the latest version (I am not sure about 45 or 57).I will add some unit tests with the intention to activate this path, so we can have more certainty about it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BTW, we can see in the same function that setuptools is already adding
license_file
tolicense_files
, so maybewheel
don't have to analyse it again...There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In 1682602, I added a check in the test suite to ensure the code path with the warning is triggered.
In 5b09d96, I removed that code path completely since it seems to already be handled by
setuptools
(as observed in https://github.com/pypa/setuptools/blob/v57.0.0/setuptools/dist.py#L583-L599 and https://github.com/pypa/setuptools/blob/2451deee140b043dcb18796eabda370806881035/setuptools/config.py#L523-L527). Setuptools uses a different warning, and depending on the version, a different warning class.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I concur. I was just looking at the coverage report and I think the
license_files
property could be eliminated entirely.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perfect.
I removed this code path.
Please let me know if you prefer to remove entirely the
test_licenses_deprecated
(this way thewheel
test suite is more independent of setuptools deprecation schedule). Tomorrow morning I can have a look at it.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, we should not be testing setuptools code in the
wheel
test suite. Chuck it out :)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in 16c90f4