Commit 77b7c39d authored by Jason R. Coombs's avatar Jason R. Coombs

Extracted _all_dirs and rewrote _find_packages_iter as a proper iterator.

parent 53ee4c9c
...@@ -53,21 +53,24 @@ def find_packages(where='.', exclude=(), include=('*',)): ...@@ -53,21 +53,24 @@ def find_packages(where='.', exclude=(), include=('*',)):
out = filterfalse(excludes, out) out = filterfalse(excludes, out)
return list(out) return list(out)
def _find_packages_iter(where): def _all_dirs(base_path):
out = [] """
stack=[(where, '')] Return all dirs in base_path, relative to base_path
while stack: """
where,prefix = stack.pop(0) for root, dirs, files in os.walk(base_path):
dirs = _dirs(where) for dir in dirs:
suitable = filterfalse(lambda n: '.' in n, dirs) yield os.path.relpath(os.path.join(root, dir), base_path)
paths = (os.path.join(where, name) for name in suitable)
packages = filter(_looks_like_package, paths) def _find_packages_iter(base_path):
for path in packages: dirs = _all_dirs(base_path)
name = os.path.basename(path) suitable = filterfalse(lambda n: '.' in n, dirs)
pkg_name = prefix + name packages = (
out.append(pkg_name) path
stack.append((path, pkg_name + '.')) for path in suitable
return out 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): def _looks_like_package(path):
return ( return (
...@@ -75,16 +78,6 @@ def _looks_like_package(path): ...@@ -75,16 +78,6 @@ def _looks_like_package(path):
or sys.version_info[:2] >= (3, 3) # PEP 420 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): def _build_filter(*patterns):
""" """
Given a list of patterns, return a callable that will be true only if Given a list of patterns, return a callable that will be true only if
......
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