diff options
| -rw-r--r-- | changelog.d/1536.change.rst | 3 | ||||
| -rw-r--r-- | docs/setuptools.txt | 1 | ||||
| -rw-r--r-- | setuptools/command/egg_info.py | 1 | ||||
| -rw-r--r-- | setuptools/command/sdist.py | 21 | ||||
| -rw-r--r-- | setuptools/tests/test_egg_info.py | 49 |
5 files changed, 75 insertions, 0 deletions
diff --git a/changelog.d/1536.change.rst b/changelog.d/1536.change.rst new file mode 100644 index 00000000..8a69959c --- /dev/null +++ b/changelog.d/1536.change.rst @@ -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``. diff --git a/docs/setuptools.txt b/docs/setuptools.txt index cf166e9c..a4e05d75 100644 --- a/docs/setuptools.txt +++ b/docs/setuptools.txt @@ -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 diff --git a/setuptools/command/egg_info.py b/setuptools/command/egg_info.py index d9fe3da3..5d8f451e 100644 --- a/setuptools/command/egg_info.py +++ b/setuptools/command/egg_info.py @@ -568,6 +568,7 @@ class manifest_maker(sdist): 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()) diff --git a/setuptools/command/sdist.py b/setuptools/command/sdist.py index bcfae4d8..dc253981 100644 --- a/setuptools/command/sdist.py +++ b/setuptools/command/sdist.py @@ -198,3 +198,24 @@ class sdist(sdist_add_defaults, orig.sdist): 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) diff --git a/setuptools/tests/test_egg_info.py b/setuptools/tests/test_egg_info.py index d5fa2558..db9c3873 100644 --- a/setuptools/tests/test_egg_info.py +++ b/setuptools/tests/test_egg_info.py @@ -518,6 +518,55 @@ class TestEggInfo: 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` |
