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

Setuptools will install licenses if included in setup.cfg #1536

Merged
merged 8 commits into from
Jan 27, 2019
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -2448,6 +2448,7 @@ maintainer str
maintainer_email maintainer-email str
classifiers classifier file:, list-comma
license file:, str
license_file str
pganssle marked this conversation as resolved.
Show resolved Hide resolved
description summary file:, str
long_description long-description file:, str
long_description_content_type str
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 @@ -6,6 +6,7 @@
import contextlib

from setuptools.extern import six
from setuptools.extern.six.moves import configparser
pganssle marked this conversation as resolved.
Show resolved Hide resolved

from .py36compat import sdist_add_defaults

Expand Down Expand Up @@ -198,3 +199,23 @@ 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')
try:
pganssle marked this conversation as resolved.
Show resolved Hide resolved
# ignore the source of the value
_, license_file = opts.get('license_file')
except TypeError:
log.debug("'license_file' attribute is not defined")
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)
51 changes: 51 additions & 0 deletions setuptools/tests/test_egg_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,57 @@ 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)
environ = os.environ.copy().update(
pganssle marked this conversation as resolved.
Show resolved Hide resolved
HOME=env.paths['home'],
)
environment.run_setup_py(
cmd=['egg_info'],
pypath=os.pathsep.join([env.paths['lib'], str(tmpdir_cwd)]),
data_stream=1,
env=environ,
)
egg_info_dir = os.path.join('.', 'foo.egg-info')
with open(os.path.join(egg_info_dir, 'SOURCES.txt')) as sources_file:
pganssle marked this conversation as resolved.
Show resolved Hide resolved
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