Commit 38a40150 authored by Jason R. Coombs's avatar Jason R. Coombs

Another refactor of findall, this time separating the simple walk / join...

Another refactor of findall, this time separating the simple walk / join operation from the conditional relative path.
parent 32a47417
...@@ -139,22 +139,29 @@ class Command(_Command): ...@@ -139,22 +139,29 @@ class Command(_Command):
# we can't patch distutils.cmd, alas # we can't patch distutils.cmd, alas
distutils.core.Command = Command distutils.core.Command = Command
def _find_all_simple(path):
"""
Find all files under 'path'
"""
return (
os.path.join(base, file)
for base, dirs, files in os.walk(path, followlinks=True)
for file in files
)
def findall(dir=os.curdir): def findall(dir=os.curdir):
""" """
Find all files under 'dir' and return the list of full filenames. Find all files under 'dir' and return the list of full filenames.
Unless dir is '.', return full filenames with dir prepended. Unless dir is '.', return full filenames with dir prepended.
""" """
def _prepend(base): files = _find_all_simple(dir)
if base == os.curdir or base.startswith(os.curdir + os.sep): if dir == os.curdir:
base = base[2:] make_rel = functools.partial(os.path.relpath, start=dir)
return functools.partial(os.path.join, base) files = map(make_rel, files)
return list(files)
return [
file
for base, dirs, files in os.walk(dir, followlinks=True)
for file in map(_prepend(base), files)
if os.path.isfile(file)
]
# fix findall bug in distutils (http://bugs.python.org/issue12885) # fix findall bug in distutils (http://bugs.python.org/issue12885)
distutils.filelist.findall = findall distutils.filelist.findall = findall
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