8000 Merge pull request #2620 from cdce8p/license-files-improments · pypa/setuptools@ee6a5ff · GitHub
[go: up one dir, main page]

Skip to content

Commit ee6a5ff

Browse files
authored
Merge pull request #2620 from cdce8p/license-files-improments
License_files improvements
2 parents 03ad13c + 608c376 commit ee6a5ff

File tree

9 files changed

+118
-27
lines changed

9 files changed

+118
-27
lines changed

changelog.d/2620.breaking.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
If neither ``license_file`` nor ``license_files`` is specified, the ``sdist``
2+
option will now auto-include files that match the following patterns:
3+
``LICEN[CS]E*``, ``COPYING*``, ``NOTICE*``, ``AUTHORS*``.
4+
This matches the behavior of ``bdist_wheel``. -- by :user:`cdce8p`

changelog.d/2620.change.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
The ``license_file`` and ``license_files`` options now support glob patterns. -- by :user:`cdce8p`

changelog.d/2620.deprecation.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
The ``license_file`` option is now marked as deprecated.
2+
Use ``license_files`` instead. -- by :user:`cdce8p`

changelog.d/2620.doc.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Added documentation for the ``license_files`` option. -- by :user:`cdce8p`

docs/references/keywords.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,17 @@ Keywords
7676
``license``
7777
A string specifying the license of the package.
7878

79+
``license_file``
80+
81+
.. warning::
82+
``license_file`` is deprecated. Use ``license_files`` instead.
83+
84+
``license_files``
85+
86+
A list of glob patterns for license related files that should be included.
87+
If neither ``license_file`` nor ``license_files`` is specified, this option
88+
defaults to ``LICEN[CS]E*``, ``COPYING*``, ``NOTICE*``, and ``AUTHORS*``.
89+
7990
``keywords``
8091
A list of strings or a comma-separated string providing descriptive
8192
meta-data. See: `PEP 0314`_.

docs/userguide/declarative_config.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ maintainer_email maintainer-email str
184184
classifiers classifier file:, list-comma
185185
license str
186186
license_file str
187-
license_files list-comma
187+
license_files list-comma 42.0.0
188188
description summary file:, str
189189
long_description long-description file:, str
190190
long_description_content_type str 38.6.0

setuptools/command/sdist.py

Lines changed: 34 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import sys
55
import io
66
import contextlib
7+
from glob import iglob
78

89
from setuptools.extern import ordered_set
910

@@ -194,29 +195,41 @@ def check_license(self):
194195
"""Checks if license_file' or 'license_files' is configured and adds any
195196
valid paths to 'self.filelist'.
196197
"""
197-
198-
files = ordered_set.OrderedSet()
199-
200198
opts = self.distribution.get_option_dict('metadata')
201199

202-
# ignore the source of the value
203-
_, license_file = opts.get('license_file', (None, None))
204-
205-
if license_file is None:
206-
log.debug("'license_file' option was not specified")
207-
else:
208-
files.add(license_file)
209-
200+
files = ordered_set.OrderedSet()
210201
try:
211-
files.update(self.distribution.metadata.license_files)
202+
license_files = self.distribution.metadata.license_files
212203
except TypeError:
213204
log.warn("warning: 'license_files' option is malformed")
214-
215-
for f in files:
216-
if not os.path.exists(f):
217-
log.warn(
218-
"warning: Failed to find the configured license file '%s'",
219-
f)
220-
files.remove(f)
221-
222-
self.filelist.extend(files)
205+
license_files = ordered_set.OrderedSet()
206+
patterns = license_files if isinstance(license_files, ordered_set.OrderedSet) \
207+
else ordered_set.OrderedSet(license_files)
208+
209+
if 'license_file' in opts:
210+
log.warn(
211+
"warning: the 'license_file' option is deprecated, "
212+
"use 'license_files' instead")
213+
patterns.append(opts['license_file'][1])
214+
215+
if 'license_file' not in opts and 'license_files' not in opts:
216+
# Default patterns match the ones wheel uses
217+
# See https://wheel.readthedocs.io/en/stable/user_guide.html
218+
# -> 'Including license files in the generated wheel file'
219+
patterns = ('LICEN[CS]E*', 'COPYING*', 'NOTICE*', 'AUTHORS*')
220+
221+
for pattern in patterns:
222+
for path in iglob(pattern):
223+
if path.endswith('~'):
224+
log.debug(
225+
"ignoring license file '%s' as it looks like a backup",
226+
path)
227+
continue
228+
229+
if path not in files and os.path.isfile(path):
230+
log.info(
231+
"adding license file '%s' (matched pattern '%s')",
232+
path, pattern)
233+
files.add(path)
234+
235+
self.filelist.extend(sorted(files))

setuptools/tests/test_egg_info.py

Lines changed: 63 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -537,15 +537,23 @@ def test_doesnt_provides_extra(self, tmpdir_cwd, env):
537537
'setup.cfg': DALS("""
538538
"""),
539539
'LICENSE': "Test license"
540-
}, False), # no license_file attribute
540+
}, True), # no license_file attribute, LICENSE auto-included
541541
({
542542
'setup.cfg': DALS("""
543543
[metadata]
544544
license_file = LICENSE
545545
"""),
546546
'MANIFEST.in': "exclude LICENSE",
547547
'LICENSE': "Test license"
548-
}, False) # license file is manually excluded
548+
}, False), # license file is manually excluded
549+
pytest.param({
550+
'setup.cfg': DALS("""
551+
[metadata]
552+
license_file = LICEN[CS]E*
553+
"""),
554+
'LICENSE': "Test license",
555+
}, True,
556+
id="glob_pattern"),
549557
])
550558
def test_setup_cfg_license_file(
551559
self, tmpdir_cwd, env, files, license_in_sources):
@@ -625,7 +633,7 @@ def test_setup_cfg_license_file(
625633
'setup.cfg': DALS("""
626634
"""),
627635
'LICENSE': "Test license"
628-
}, [], ['LICENSE']), # no license_files attribute
636+
}, ['LICENSE'], []), # no license_files attribute, LICENSE auto-included
629637
({
630638
'setup.cfg': DALS("""
631639
[metadata]
@@ -644,7 +652,36 @@ def test_setup_cfg_license_file(
644652
'MANIFEST.in': "exclude LICENSE-XYZ",
645653
'LICENSE-ABC': "ABC license",
646654
'LICENSE-XYZ': "XYZ license"
647-
}, ['LICENSE-ABC'], ['LICENSE-XYZ']) # subset is manually excluded
655+
}, ['LICENSE-ABC'], ['LICENSE-XYZ']), # subset is manually excluded
656+
pytest.param({
657+
'setup.cfg': "",
658+
'LICENSE-ABC': "ABC license",
659+
'COPYING-ABC': "ABC copying",
660+
'NOTICE-ABC': "ABC notice",
661+
'AUTHORS-ABC': "ABC authors",
662+
'LICENCE-XYZ': "XYZ license",
663+
'LICENSE': "License",
664+
'INVALID-LICENSE': "Invalid license",
665+
}, [
666+
'LICENSE-ABC',
667+
'COPYING-ABC',
668+
'NOTICE-ABC',
669+
'AUTHORS-ABC',
670+
'LICENCE-XYZ',
671+
'LICENSE',
672+
], ['INVALID-LICENSE'],
673+
# ('LICEN[CS]E*', 'COPYING*', 'NOTICE*', 'AUTHORS*')
674+
id="default_glob_patterns"),
675+
pytest.param({
676+
'setup.cfg': DALS("""
677+
[metadata]
678+
license_files =
679+
LICENSE*
680+
"""),
681+
'LICENSE-ABC': "ABC license",
682+
'NOTICE-XYZ': "XYZ notice",
683+
}, ['LICENSE-ABC'], ['NOTICE-XYZ'],
684+
id="no_default_glob_patterns"),
648685
])
649686
def test_setup_cfg_license_files(
650687
self, tmpdir_cwd, env, files, incl_licenses, excl_licenses):
@@ -749,7 +786,28 @@ def test_setup_cfg_license_files(
749786
'LICENSE-PQR': "PQR license",
750787
'LICENSE-XYZ': "XYZ license"
751788
# manually excluded
752-
}, ['LICENSE-XYZ'], ['LICENSE-ABC', 'LICENSE-PQR'])
789+
}, ['LICENSE-XYZ'], ['LICENSE-ABC', 'LICENSE-PQR']),
790+
pytest.param({
791+
'setup.cfg': DALS("""
792+
[metadata]
793+
license_file = LICENSE*
794+
"""),
795+
'LICENSE-ABC': "ABC license",
796+
'NOTICE-XYZ': "XYZ notice",
797+
}, ['LICENSE-ABC'], ['NOTICE-XYZ'],
798+
id="no_default_glob_patterns"),
799+
pytest.param({
800+
'setup.cfg': DALS("""
801+
[metadata]
802+
license_file = LICENSE*
803+
license_files =
804+
NOTICE*
805+
"""),
806+
'LICENSE-ABC': "ABC license",
807+
'NOTICE-ABC': "ABC notice",
808+
'AUTHORS-ABC': "ABC authors",
809+
}, ['LICENSE-ABC', 'NOTICE-ABC'], ['AUTHORS-ABC'],
810+
id="combined_glob_patterrns"),
753811
])
754812
def test_setup_cfg_license_file_license_files(
755813
self, tmpdir_cwd, env, files, incl_licenses, excl_licenses):

setuptools/tests/test_manifest.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ def touch(filename):
5555
default_files = frozenset(map(make_local_path, [
5656
'README.rst',
5757
'MANIFEST.in',
58+
'LICENSE',
5859
'setup.py',
5960
'app.egg-info/PKG-INFO',
6061
'app.egg-info/SOURCES.txt',

0 commit comments

Comments
 (0)
0