Commit b0c3783b authored by PJ Eby's avatar PJ Eby

Added ``exclude=patternlist`` option to ``setuptools.find_packages()``

--HG--
branch : setuptools
extra : convert_revision : svn%3A6015fed2-1504-0410-9fe1-9d1591cc4771/sandbox/trunk/setuptools%4041102
parent 72de8511
"""Extensions to the 'distutils' for large or complex distributions""" """Extensions to the 'distutils' for large or complex distributions"""
import distutils.core, setuptools.command import distutils.core, setuptools.command
from setuptools.dist import Distribution, Feature from setuptools.dist import Distribution, Feature
from setuptools.extension import Extension from setuptools.extension import Extension
...@@ -9,7 +8,6 @@ from distutils.util import convert_path ...@@ -9,7 +8,6 @@ from distutils.util import convert_path
import os.path import os.path
__version__ = '0.5a8' __version__ = '0.5a8'
__all__ = [ __all__ = [
'setup', 'Distribution', 'Feature', 'Command', 'Extension', 'Require', 'setup', 'Distribution', 'Feature', 'Command', 'Extension', 'Require',
'find_packages' 'find_packages'
...@@ -17,16 +15,17 @@ __all__ = [ ...@@ -17,16 +15,17 @@ __all__ = [
bootstrap_install_from = None bootstrap_install_from = None
def find_packages(where='.'): def find_packages(where='.', exclude=()):
"""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
will be converted to the appropriate local path syntax. will be converted to the appropriate local path syntax. 'exclude' is a
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).
""" """
out = [] out = []
stack=[(convert_path(where), '')] stack=[(convert_path(where), '')]
while stack: while stack:
where,prefix = stack.pop(0) where,prefix = stack.pop(0)
for name in os.listdir(where): for name in os.listdir(where):
...@@ -35,10 +34,11 @@ def find_packages(where='.'): ...@@ -35,10 +34,11 @@ def find_packages(where='.'):
os.path.isfile(os.path.join(fn,'__init__.py')) os.path.isfile(os.path.join(fn,'__init__.py'))
): ):
out.append(prefix+name); stack.append((fn,prefix+name+'.')) out.append(prefix+name); stack.append((fn,prefix+name+'.'))
for pat in exclude:
from fnmatch import fnmatchcase
out = [item for item in out if not fnmatchcase(item,pat)]
return out return out
def setup(**attrs): def setup(**attrs):
"""Do package setup """Do package setup
......
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