aboutsummaryrefslogtreecommitdiffstats
path: root/setuptools/__init__.py
diff options
context:
space:
mode:
authorWyatt Lee Baldwin <self@wyattbaldwin.com>2014-02-12 00:52:26 -0800
committerWyatt Lee Baldwin <self@wyattbaldwin.com>2014-02-12 00:52:26 -0800
commitcc20858d5ead318ae7e8ddcdaf61c610fa1e0578 (patch)
tree479cc6d0a8be18eb5587442718f37c1cd1083593 /setuptools/__init__.py
parent193b2ee5695838d25f99ddc3dbf22deeb97eafe0 (diff)
downloadexternal_python_setuptools-cc20858d5ead318ae7e8ddcdaf61c610fa1e0578.tar.gz
external_python_setuptools-cc20858d5ead318ae7e8ddcdaf61c610fa1e0578.tar.bz2
external_python_setuptools-cc20858d5ead318ae7e8ddcdaf61c610fa1e0578.zip
Add include parameter to find_packages.
--HG-- extra : rebase_source : 1fec39a038ac2c460e62ef2ee2eee5a0b66a676d
Diffstat (limited to 'setuptools/__init__.py')
-rw-r--r--setuptools/__init__.py18
1 files changed, 15 insertions, 3 deletions
diff --git a/setuptools/__init__.py b/setuptools/__init__.py
index c5b00ba5..a96e4c9d 100644
--- a/setuptools/__init__.py
+++ b/setuptools/__init__.py
@@ -28,7 +28,7 @@ run_2to3_on_doctests = True
# Standard package names for fixer packages
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'
'where' should be supplied as a "cross-platform" (i.e. URL-style) path; it
@@ -36,9 +36,18 @@ def find_packages(where='.', exclude=()):
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
'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 = []
stack=[(convert_path(where), '')]
+ include = list(include)
exclude = list(exclude) + ['ez_setup', '*__pycache__']
while stack:
where,prefix = stack.pop(0)
@@ -50,8 +59,11 @@ def find_packages(where='.', exclude=()):
and os.path.isfile(os.path.join(fn, '__init__.py'))
)
if looks_like_package:
- out.append(prefix+name)
- stack.append((fn, prefix+name+'.'))
+ pkg_name = 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:
out = [item for item in out if not fnmatchcase(item,pat)]
return out