diff options
| author | Marc Mueller <30130371+cdce8p@users.noreply.github.com> | 2021-05-22 12:23:18 +0200 |
|---|---|---|
| committer | Marc Mueller <30130371+cdce8p@users.noreply.github.com> | 2021-05-22 12:48:32 +0200 |
| commit | c1435f2ed038d3df31f3774faac4a0ef43868e06 (patch) | |
| tree | 4e3650e677d7f7c161eeafa462f211f995e86af3 | |
| parent | 57d51d364a4f9d953dbf8d5ffe14ae944f549ebf (diff) | |
| download | python-setuptools-git-c1435f2ed038d3df31f3774faac4a0ef43868e06.tar.gz | |
Keep user sorting for license files
| -rw-r--r-- | setuptools/dist.py | 14 | ||||
| -rw-r--r-- | setuptools/tests/test_egg_info.py | 26 |
2 files changed, 29 insertions, 11 deletions
diff --git a/setuptools/dist.py b/setuptools/dist.py index 8afbc7a5..306c9671 100644 --- a/setuptools/dist.py +++ b/setuptools/dist.py @@ -573,13 +573,13 @@ class Distribution(_Distribution): def _finalize_license_files(self): """Compute names of all license files which should be included.""" - files = set() + files: List[str] = [] license_files: Optional[List[str]] = self.metadata.license_files - patterns: Set[str] = set(license_files) if license_files else set() + patterns: List[str] = license_files if license_files else [] license_file: Optional[str] = self.metadata.license_file - if license_file: - patterns.add(license_file) + if license_file and license_file not in patterns: + patterns.append(license_file) if license_files is None and license_file is None: # Default patterns match the ones wheel uses @@ -588,13 +588,15 @@ class Distribution(_Distribution): patterns = ('LICEN[CS]E*', 'COPYING*', 'NOTICE*', 'AUTHORS*') for pattern in patterns: + files_pattern: Set[str] = set() for path in iglob(pattern): if path.endswith('~'): continue if path not in files and os.path.isfile(path): - files.add(path) + files_pattern.add(path) + files.extend(sorted(files_pattern)) - self.metadata.license_files = sorted(files) + self.metadata.license_files = files # FIXME: 'Distribution._parse_config_files' is too complex (14) def _parse_config_files(self, filenames=None): # noqa: C901 diff --git a/setuptools/tests/test_egg_info.py b/setuptools/tests/test_egg_info.py index a22ba04f..e0d6b45e 100644 --- a/setuptools/tests/test_egg_info.py +++ b/setuptools/tests/test_egg_info.py @@ -689,6 +689,17 @@ class TestEggInfo: 'NOTICE-XYZ': "XYZ notice", }, ['LICENSE-ABC'], ['NOTICE-XYZ'], id="no_default_glob_patterns"), + pytest.param({ + 'setup.cfg': DALS(""" + [metadata] + license_files = + LICENSE-ABC + LICENSE* + """), + 'LICENSE-ABC': "ABC license", + }, ['LICENSE-ABC'], [], + id="files_only_added_once", + ), ]) def test_setup_cfg_license_files( self, tmpdir_cwd, env, files, incl_licenses, excl_licenses): @@ -843,11 +854,13 @@ class TestEggInfo: "setup.cfg": DALS(""" [metadata] license_files = + NOTICE* LICENSE* """), "LICENSE-ABC": "ABC license", "LICENSE-XYZ": "XYZ license", - "NOTICE": "not included", + "NOTICE": "included", + "IGNORE": "not include", }) environment.run_setup_py( @@ -860,10 +873,13 @@ class TestEggInfo: license_file_lines = [ line for line in pkg_info_lines if line.startswith('License-File:')] - # Only 'LICENSE-ABC' and 'LICENSE-XYZ' should have been matched - assert len(license_file_lines) == 2 - assert "License-File: LICENSE-ABC" in license_file_lines - assert "License-File: LICENSE-XYZ" in license_file_lines + # Only 'NOTICE', LICENSE-ABC', and 'LICENSE-XYZ' should have been matched + # Also assert that order from license_files is keeped + assert license_file_lines == [ + "License-File: NOTICE", + "License-File: LICENSE-ABC", + "License-File: LICENSE-XYZ", + ] def test_metadata_version(self, tmpdir_cwd, env): """Make sure latest metadata version is used by default.""" |
