Commit e75bb059 authored by Jason R. Coombs's avatar Jason R. Coombs

Re-use unique_everseen from itertools recipes.

parent 1af011b1
......@@ -6,10 +6,9 @@ import fnmatch
import textwrap
import io
import distutils.errors
import collections
import itertools
from setuptools.extern.six.moves import map, filter
from setuptools.extern.six.moves import map, filter, filterfalse
try:
from setuptools.lib2to3_ex import Mixin2to3
......@@ -204,14 +203,13 @@ class build_py(orig.build_py, Mixin2to3):
# flatten the groups of matches into an iterable of matches
matches = itertools.chain.from_iterable(match_groups)
bad = set(matches)
seen = collections.defaultdict(itertools.count)
return [
keepers = (
fn
for fn in files
if fn not in bad
# ditch dupes
and not next(seen[fn])
]
)
# ditch dupes
return list(_unique_everseen(keepers))
@staticmethod
def _get_platform_patterns(spec, package, src_dir):
......@@ -232,6 +230,25 @@ class build_py(orig.build_py, Mixin2to3):
)
# from Python docs
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 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
def assert_relative(path):
if not os.path.isabs(path):
return path
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment