Commit cc20858d authored by Wyatt Lee Baldwin's avatar Wyatt Lee Baldwin

Add include parameter to find_packages.

--HG--
extra : rebase_source : 1fec39a038ac2c460e62ef2ee2eee5a0b66a676d
parent 193b2ee5
...@@ -2,6 +2,12 @@ ...@@ -2,6 +2,12 @@
CHANGES CHANGES
======= =======
---
3.3
---
* Add ``include`` parameter to ``setuptools.find_packages()``.
--- ---
3.2 3.2
--- ---
......
...@@ -28,7 +28,7 @@ run_2to3_on_doctests = True ...@@ -28,7 +28,7 @@ run_2to3_on_doctests = True
# Standard package names for fixer packages # Standard package names for fixer packages
lib2to3_fixer_packages = ['lib2to3.fixes'] lib2to3_fixer_packages = ['lib2to3.fixes']
def find_packages(where='.', exclude=()): def find_packages(where='.', exclude=(), include=()):
"""Return a list all Python packages found within directory 'where' """Return a list all Python packages found within directory 'where'
'where' should be supplied as a "cross-platform" (i.e. URL-style) path; it 'where' should be supplied as a "cross-platform" (i.e. URL-style) path; it
...@@ -36,9 +36,18 @@ def find_packages(where='.', exclude=()): ...@@ -36,9 +36,18 @@ def find_packages(where='.', exclude=()):
sequence of package names to exclude; '*' can be used as a wildcard in the sequence of package names to exclude; '*' can be used as a wildcard in the
names, such that 'foo.*' will exclude all subpackages of 'foo' (but not names, such that 'foo.*' will exclude all subpackages of 'foo' (but not
'foo' itself). 'foo' itself).
'include' is a sequence of package names to include. If it's specified,
only the named packages will be included. If it's not specified, all found
packages will be included. 'include' can contain shell style wildcard
patterns just like 'exclude'.
The list of included packages is built up first and then any explicitly
excluded packages are removed from it.
""" """
out = [] out = []
stack=[(convert_path(where), '')] stack=[(convert_path(where), '')]
include = list(include)
exclude = list(exclude) + ['ez_setup', '*__pycache__'] exclude = list(exclude) + ['ez_setup', '*__pycache__']
while stack: while stack:
where,prefix = stack.pop(0) where,prefix = stack.pop(0)
...@@ -50,8 +59,11 @@ def find_packages(where='.', exclude=()): ...@@ -50,8 +59,11 @@ def find_packages(where='.', exclude=()):
and os.path.isfile(os.path.join(fn, '__init__.py')) and os.path.isfile(os.path.join(fn, '__init__.py'))
) )
if looks_like_package: if looks_like_package:
out.append(prefix+name) pkg_name = prefix + name
stack.append((fn, prefix+name+'.')) if (not include or
any(fnmatchcase(pkg_name, pat) for pat in include)):
out.append(pkg_name)
stack.append((fn, pkg_name + '.'))
for pat in exclude: for pat in exclude:
out = [item for item in out if not fnmatchcase(item,pat)] out = [item for item in out if not fnmatchcase(item,pat)]
return out return out
......
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