summaryrefslogtreecommitdiff
path: root/Lib/distutils
diff options
context:
space:
mode:
authorJason R. Coombs <jaraco@jaraco.com>2015-09-19 18:12:15 +0200
committerJason R. Coombs <jaraco@jaraco.com>2015-09-19 18:12:15 +0200
commitedc4b2fa675788486cea661b4c6b9f7e33c44a3f (patch)
tree3bcc11b9a9aebdea5ad8f36516aee97c1e632217 /Lib/distutils
parent1a04c447c951b33aa8c8c0f1b6803b06101b7f92 (diff)
downloadcpython-git-edc4b2fa675788486cea661b4c6b9f7e33c44a3f.tar.gz
Issue #12285: Replace implementation of findall with implementation from Setuptools 7ce820d524db.
Diffstat (limited to 'Lib/distutils')
-rw-r--r--Lib/distutils/filelist.py48
1 files changed, 21 insertions, 27 deletions
diff --git a/Lib/distutils/filelist.py b/Lib/distutils/filelist.py
index db3f7a9680..6522e69f06 100644
--- a/Lib/distutils/filelist.py
+++ b/Lib/distutils/filelist.py
@@ -6,6 +6,7 @@ and building lists of files.
import os, re
import fnmatch
+import functools
from distutils.util import convert_path
from distutils.errors import DistutilsTemplateError, DistutilsInternalError
from distutils import log
@@ -242,35 +243,28 @@ class FileList:
# ----------------------------------------------------------------------
# Utility functions
+def _find_all_simple(path):
+ """
+ Find all files under 'path'
+ """
+ results = (
+ os.path.join(base, file)
+ for base, dirs, files in os.walk(path, followlinks=True)
+ for file in files
+ )
+ return filter(os.path.isfile, results)
+
+
def findall(dir=os.curdir):
- """Find all files under 'dir' and return the list of full filenames
- (relative to 'dir').
"""
- from stat import ST_MODE, S_ISREG, S_ISDIR, S_ISLNK
-
- list = []
- stack = [dir]
- pop = stack.pop
- push = stack.append
-
- while stack:
- dir = pop()
- names = os.listdir(dir)
-
- for name in names:
- if dir != os.curdir: # avoid the dreaded "./" syndrome
- fullname = os.path.join(dir, name)
- else:
- fullname = name
-
- # Avoid excess stat calls -- just one will do, thank you!
- stat = os.stat(fullname)
- mode = stat[ST_MODE]
- if S_ISREG(mode):
- list.append(fullname)
- elif S_ISDIR(mode) and not S_ISLNK(mode):
- push(fullname)
- return list
+ Find all files under 'dir' and return the list of full filenames.
+ Unless dir is '.', return full filenames with dir prepended.
+ """
+ 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)
def glob_to_re(pattern):