Commit 97e8ad4f authored by Jason R. Coombs's avatar Jason R. Coombs Committed by GitHub

Merge pull request #1536 from dtaneli/license-fix-357

Setuptools will install licenses if included in setup.cfg
parents 78fd7302 0551421f
``setuptools`` will now automatically include licenses if ``setup.cfg``
contains a ``license_file`` attribute, unless this file is manually excluded
inside ``MANIFEST.in``.
...@@ -2371,6 +2371,7 @@ maintainer str ...@@ -2371,6 +2371,7 @@ maintainer str
maintainer_email maintainer-email str maintainer_email maintainer-email str
classifiers classifier file:, list-comma classifiers classifier file:, list-comma
license str license str
license_file str
description summary file:, str description summary file:, str
long_description long-description file:, str long_description long-description file:, str
long_description_content_type str 38.6.0 long_description_content_type str 38.6.0
......
...@@ -568,6 +568,7 @@ class manifest_maker(sdist): ...@@ -568,6 +568,7 @@ class manifest_maker(sdist):
def add_defaults(self): def add_defaults(self):
sdist.add_defaults(self) sdist.add_defaults(self)
self.check_license()
self.filelist.append(self.template) self.filelist.append(self.template)
self.filelist.append(self.manifest) self.filelist.append(self.manifest)
rcfiles = list(walk_revctrl()) rcfiles = list(walk_revctrl())
......
...@@ -198,3 +198,24 @@ class sdist(sdist_add_defaults, orig.sdist): ...@@ -198,3 +198,24 @@ class sdist(sdist_add_defaults, orig.sdist):
continue continue
self.filelist.append(line) self.filelist.append(line)
manifest.close() manifest.close()
def check_license(self):
"""Checks if license_file' is configured and adds it to
'self.filelist' if the value contains a valid path.
"""
opts = self.distribution.get_option_dict('metadata')
# ignore the source of the value
_, license_file = opts.get('license_file', (None, None))
if license_file is None:
log.debug("'license_file' option was not specified")
return
if not os.path.exists(license_file):
log.warn("warning: Failed to find the configured license file '%s'",
license_file)
return
self.filelist.append(license_file)
...@@ -518,6 +518,55 @@ class TestEggInfo: ...@@ -518,6 +518,55 @@ class TestEggInfo:
pkg_info_text = pkginfo_file.read() pkg_info_text = pkginfo_file.read()
assert 'Provides-Extra:' not in pkg_info_text assert 'Provides-Extra:' not in pkg_info_text
@pytest.mark.parametrize("files, license_in_sources", [
({
'setup.cfg': DALS("""
[metadata]
license_file = LICENSE
"""),
'LICENSE': DALS("Test license")
}, True), # with license
({
'setup.cfg': DALS("""
[metadata]
license_file = INVALID_LICENSE
"""),
'LICENSE': DALS("Test license")
}, False), # with an invalid license
({
'setup.cfg': DALS("""
"""),
'LICENSE': DALS("Test license")
}, False), # no license_file attribute
({
'setup.cfg': DALS("""
[metadata]
license_file = LICENSE
"""),
'MANIFEST.in': DALS("exclude LICENSE"),
'LICENSE': DALS("Test license")
}, False) # license file is manually excluded
])
def test_setup_cfg_license_file(
self, tmpdir_cwd, env, files, license_in_sources):
self._create_project()
build_files(files)
environment.run_setup_py(
cmd=['egg_info'],
pypath=os.pathsep.join([env.paths['lib'], str(tmpdir_cwd)])
)
egg_info_dir = os.path.join('.', 'foo.egg-info')
with open(os.path.join(egg_info_dir, 'SOURCES.txt')) as sources_file:
sources_text = sources_file.read()
if license_in_sources:
assert 'LICENSE' in sources_text
else:
assert 'LICENSE' not in sources_text
assert 'INVALID_LICENSE' not in sources_text # for invalid license test
def test_long_description_content_type(self, tmpdir_cwd, env): def test_long_description_content_type(self, tmpdir_cwd, env):
# Test that specifying a `long_description_content_type` keyword arg to # Test that specifying a `long_description_content_type` keyword arg to
# the `setup` function results in writing a `Description-Content-Type` # the `setup` function results in writing a `Description-Content-Type`
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment