diff options
author | Jason R. Coombs <jaraco@jaraco.com> | 2021-05-22 18:54:37 -0400 |
---|---|---|
committer | Marc Mueller <30130371+cdce8p@users.noreply.github.com> | 2021-05-23 01:42:45 +0200 |
commit | 4429ffbb700c1838ddf57c47c378bd3c617eb8c3 (patch) | |
tree | 7f9c2e81b1b25bfcf2979d34d8b9265b964fe191 /setuptools/dist.py | |
parent | c837956cd9f623815df6b2155efac6e13b5e1f7b (diff) | |
download | python-setuptools-git-4429ffbb700c1838ddf57c47c378bd3c617eb8c3.tar.gz |
Replace for/if/add/extend with generator on patterns. Use unique_everseen to dedupe.
Diffstat (limited to 'setuptools/dist.py')
-rw-r--r-- | setuptools/dist.py | 41 |
1 files changed, 30 insertions, 11 deletions
diff --git a/setuptools/dist.py b/setuptools/dist.py index 65e6d8b2..067d7f5b 100644 --- a/setuptools/dist.py +++ b/setuptools/dist.py @@ -18,7 +18,7 @@ from distutils.fancy_getopt import translate_longopt from glob import iglob import itertools import textwrap -from typing import List, Optional, Set, TYPE_CHECKING +from typing import List, Optional, TYPE_CHECKING from collections import defaultdict from email import message_from_file @@ -581,7 +581,6 @@ class Distribution(_Distribution): def _finalize_license_files(self): """Compute names of all license files which should be included.""" - files: List[str] = [] license_files: Optional[List[str]] = self.metadata.license_files patterns: List[str] = license_files if license_files else [] @@ -595,16 +594,18 @@ class Distribution(_Distribution): # -> 'Including license files in the generated wheel file' 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_pattern.add(path) - files.extend(sorted(files_pattern)) + self.metadata.license_files = list( + unique_everseen(self._expand_patterns(patterns))) - self.metadata.license_files = files + @staticmethod + def _expand_patterns(patterns): + return ( + path + for pattern in patterns + for path in iglob(pattern) + if not path.endswith('~') + and os.path.isfile(path) + ) # FIXME: 'Distribution._parse_config_files' is too complex (14) def _parse_config_files(self, filenames=None): # noqa: C901 @@ -1111,3 +1112,21 @@ class Distribution(_Distribution): class DistDeprecationWarning(SetuptoolsDeprecationWarning): """Class for warning about deprecations in dist in setuptools. Not ignored by default, unlike DeprecationWarning.""" + + +def unique_everseen(iterable, key=None): + "List unique elements, preserving order. Remember all elements ever seen." + # unique_everseen('AAAABBBCCDAABBB') --> A B C D + # unique_everseen('ABBCcAD', str.lower) --> A B C D + seen = set() + seen_add = seen.add + if key is None: + for element in itertools.filterfalse(seen.__contains__, iterable): + seen_add(element) + yield element + else: + for element in iterable: + k = key(element) + if k not in seen: + seen_add(k) + yield element |