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

Replace for/if/add/extend with generator on patterns. #1

Merged
merged 1 commit into from
May 22, 2021
Merged
Changes from all 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
41 changes: 30 additions & 11 deletions setuptools/dist.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
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
Expand Down Expand Up @@ -573,7 +573,6 @@ def _clean_req(self, req):

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 []

Expand All @@ -587,16 +586,18 @@ def _finalize_license_files(self):
# -> '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
Expand Down Expand Up @@ -1103,3 +1104,21 @@ def handle_display_options(self, option_order):
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