diff options
author | Jason R. Coombs <jaraco@jaraco.com> | 2014-03-22 09:52:51 -0400 |
---|---|---|
committer | Jason R. Coombs <jaraco@jaraco.com> | 2014-03-22 09:52:51 -0400 |
commit | 77b7c39d468a1065cb3cf10386ea4ddd185114b7 (patch) | |
tree | de8efe23b53f4d30fbe4a6d99e4186669a0eca57 | |
parent | 53ee4c9c87337d60d66ecca05450f4936c7c7465 (diff) | |
download | external_python_setuptools-77b7c39d468a1065cb3cf10386ea4ddd185114b7.tar.gz external_python_setuptools-77b7c39d468a1065cb3cf10386ea4ddd185114b7.tar.bz2 external_python_setuptools-77b7c39d468a1065cb3cf10386ea4ddd185114b7.zip |
Extracted _all_dirs and rewrote _find_packages_iter as a proper iterator.
-rw-r--r-- | setuptools/__init__.py | 43 |
1 files changed, 18 insertions, 25 deletions
diff --git a/setuptools/__init__.py b/setuptools/__init__.py index dbe4368c..05a14329 100644 --- a/setuptools/__init__.py +++ b/setuptools/__init__.py @@ -53,21 +53,24 @@ def find_packages(where='.', exclude=(), include=('*',)): out = filterfalse(excludes, out) return list(out) -def _find_packages_iter(where): - out = [] - stack=[(where, '')] - while stack: - where,prefix = stack.pop(0) - dirs = _dirs(where) - suitable = filterfalse(lambda n: '.' in n, dirs) - paths = (os.path.join(where, name) for name in suitable) - packages = filter(_looks_like_package, paths) - for path in packages: - name = os.path.basename(path) - pkg_name = prefix + name - out.append(pkg_name) - stack.append((path, pkg_name + '.')) - return out +def _all_dirs(base_path): + """ + Return all dirs in base_path, relative to base_path + """ + for root, dirs, files in os.walk(base_path): + for dir in dirs: + yield os.path.relpath(os.path.join(root, dir), base_path) + +def _find_packages_iter(base_path): + dirs = _all_dirs(base_path) + suitable = filterfalse(lambda n: '.' in n, dirs) + packages = ( + path + for path in suitable + if _looks_like_package(os.path.join(base_path, path)) + ) + for pkg_path in packages: + yield pkg_path.replace(os.path.sep, '.') def _looks_like_package(path): return ( @@ -75,16 +78,6 @@ def _looks_like_package(path): or sys.version_info[:2] >= (3, 3) # PEP 420 ) -def _dirs(target): - """ - Return all directories in target - """ - return ( - fn - for fn in os.listdir(target) - if os.path.isdir(os.path.join(target, fn)) - ) - def _build_filter(*patterns): """ Given a list of patterns, return a callable that will be true only if |