Skip to content

Commit

Permalink
Merge pull request #1536 from dtaneli/license-fix-357
Browse files Browse the repository at this point in the history
Setuptools will install licenses if included in setup.cfg
  • Loading branch information
jaraco authored Jan 27, 2019
2 parents 78fd730 + 0551421 commit 97e8ad4
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 0 deletions.
3 changes: 3 additions & 0 deletions changelog.d/1536.change.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
``setuptools`` will now automatically include licenses if ``setup.cfg``
contains a ``license_file`` attribute, unless this file is manually excluded
inside ``MANIFEST.in``.
1 change: 1 addition & 0 deletions docs/setuptools.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2371,6 +2371,7 @@ maintainer str
maintainer_email maintainer-email str
classifiers classifier file:, list-comma
license str
license_file str
description summary file:, str
long_description long-description file:, str
long_description_content_type str 38.6.0
Expand Down
1 change: 1 addition & 0 deletions setuptools/command/egg_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,7 @@ def _should_suppress_warning(msg):

def add_defaults(self):
sdist.add_defaults(self)
self.check_license()
self.filelist.append(self.template)
self.filelist.append(self.manifest)
rcfiles = list(walk_revctrl())
Expand Down
21 changes: 21 additions & 0 deletions setuptools/command/sdist.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,3 +198,24 @@ def read_manifest(self):
continue
self.filelist.append(line)
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)
49 changes: 49 additions & 0 deletions setuptools/tests/test_egg_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,55 @@ def test_doesnt_provides_extra(self, tmpdir_cwd, env):
pkg_info_text = pkginfo_file.read()
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):
# Test that specifying a `long_description_content_type` keyword arg to
# the `setup` function results in writing a `Description-Content-Type`
Expand Down

0 comments on commit 97e8ad4

Please sign in to comment.