summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGES.txt6
-rw-r--r--setuptools/__init__.py18
2 files changed, 21 insertions, 3 deletions
diff --git a/CHANGES.txt b/CHANGES.txt
index f5b220d9..960e5d9b 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -3,6 +3,12 @@ CHANGES
=======
---
+3.3
+---
+
+* Add ``include`` parameter to ``setuptools.find_packages()``.
+
+---
3.2
---
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