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

Rewrite find_data_files and exclude_data_files to follow the same pattern for...

Rewrite find_data_files and exclude_data_files to follow the same pattern for building platform_patterns.
parent ba0b4d2e
...@@ -94,15 +94,17 @@ class build_py(orig.build_py, Mixin2to3): ...@@ -94,15 +94,17 @@ class build_py(orig.build_py, Mixin2to3):
def find_data_files(self, package, src_dir): def find_data_files(self, package, src_dir):
"""Return filenames for package's data files in 'src_dir'""" """Return filenames for package's data files in 'src_dir'"""
globs = itertools.chain( spec = self.package_data
self.package_data.get('', []), raw_patterns = itertools.chain(
self.package_data.get(package, []), spec.get('', []),
spec.get(package, []),
) )
globs_expanded = ( platform_patterns = (
# Each pattern has to be converted to a platform-specific path # Each pattern has to be converted to a platform-specific path
glob(os.path.join(src_dir, convert_path(pattern))) os.path.join(src_dir, convert_path(pattern))
for pattern in globs for pattern in raw_patterns
) )
globs_expanded = map(glob, platform_patterns)
# flatten the expanded globs into an iterable of matches # flatten the expanded globs into an iterable of matches
globs_matches = itertools.chain.from_iterable(globs_expanded) globs_matches = itertools.chain.from_iterable(globs_expanded)
glob_files = filter(os.path.isfile, globs_matches) glob_files = filter(os.path.isfile, globs_matches)
...@@ -194,19 +196,24 @@ class build_py(orig.build_py, Mixin2to3): ...@@ -194,19 +196,24 @@ class build_py(orig.build_py, Mixin2to3):
def exclude_data_files(self, package, src_dir, files): def exclude_data_files(self, package, src_dir, files):
"""Filter filenames for package's data files in 'src_dir'""" """Filter filenames for package's data files in 'src_dir'"""
globs = itertools.chain(
self.exclude_package_data.get('', []),
self.exclude_package_data.get(package, []),
)
files = list(files) files = list(files)
bad = set( spec = self.exclude_package_data
item raw_patterns = itertools.chain(
for pattern in globs spec.get('', []),
for item in fnmatch.filter( spec.get(package, []),
files, )
os.path.join(src_dir, convert_path(pattern)), platform_patterns = (
) # Each pattern has to be converted to a platform-specific path
os.path.join(src_dir, convert_path(pattern))
for pattern in raw_patterns
)
match_groups = (
fnmatch.filter(files, pattern)
for pattern in platform_patterns
) )
# 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) seen = collections.defaultdict(itertools.count)
return [ return [
fn fn
......
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