summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason R. Coombs <jaraco@jaraco.com>2015-09-07 01:16:14 -0400
committerJason R. Coombs <jaraco@jaraco.com>2015-09-07 01:16:14 -0400
commitf9b6623fb11b6610a42bebcaaed4bdaccff170c6 (patch)
tree8bfae106020d25c9d2e107073a3fe272518e302b
parent37caa56e2e068373d596a7d82a93214511dc781f (diff)
downloadpython-setuptools-bitbucket-f9b6623fb11b6610a42bebcaaed4bdaccff170c6.tar.gz
Another refactor of findall, this time separating the simple walk / join operation from the conditional relative path.
-rw-r--r--setuptools/__init__.py29
1 files changed, 18 insertions, 11 deletions
diff --git a/setuptools/__init__.py b/setuptools/__init__.py
index 49002619..a7d75ed4 100644
--- a/setuptools/__init__.py
+++ b/setuptools/__init__.py
@@ -139,22 +139,29 @@ class Command(_Command):
# we can't patch distutils.cmd, alas
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):
"""
Find all files under 'dir' and return the list of full filenames.
Unless dir is '.', return full filenames with dir prepended.
"""
- def _prepend(base):
- if base == os.curdir or base.startswith(os.curdir + os.sep):
- base = base[2:]
- return functools.partial(os.path.join, base)
-
- return [
- file
- for base, dirs, files in os.walk(dir, followlinks=True)
- for file in map(_prepend(base), files)
- if os.path.isfile(file)
- ]
+ files = _find_all_simple(dir)
+ if dir == os.curdir:
+ make_rel = functools.partial(os.path.relpath, start=dir)
+ files = map(make_rel, files)
+ return list(files)
+
# fix findall bug in distutils (http://bugs.python.org/issue12885)
distutils.filelist.findall = findall