diff --git a/pydoctor/driver.py b/pydoctor/driver.py index c520d07..62ec1cd 100644 --- a/pydoctor/driver.py +++ b/pydoctor/driver.py @@ -1,7 +1,7 @@ """The command-line parsing and entry point.""" from pydoctor import model, zopeinterface -import sys, os +import sys, os, re def error(msg, *args): if args: @@ -98,6 +98,11 @@ def getparser(): metavar='MODULE', default=[], help=("Add a module to the system. Can be repeated.")) parser.add_option( + '--exclude', action='append', dest='exclude', + metavar='EXCLUDEDPATTERN', default=[], + help=("Exclude packages and modules matching this regex. " + "Can be repeated to exclude multiple packages/modules")) + parser.add_option( '--prepend-package', action='store', dest='prependedpackage', help=("Pretend that all packages are within this one. " "Can be used to document part of a package.")) @@ -295,6 +300,14 @@ def main(args): else: options.makehtml = False + # step 1.9: make regex excludes + if options.exclude: + try: + options.exclude = map(re.compile, options.exclude) + except re.error, e: + error("Exclude options must be valid regular " + "expressions. Error: %s" % e) + # step 2: add any packages and modules if args: diff --git a/pydoctor/model.py b/pydoctor/model.py index caa15c3..1a55828 100644 --- a/pydoctor/model.py +++ b/pydoctor/model.py @@ -546,6 +546,10 @@ class System(object): if not os.path.exists(os.path.join(dirpath, '__init__.py')): raise Exception("you must pass a package directory to " "addPackage") + + if self.shouldExclude(dirpath): + return + package = self.Package(self, os.path.basename(dirpath), None, parentPackage) self.addObject(package) @@ -558,8 +562,18 @@ class System(object): if os.path.exists(initname): self.addPackage(fullname, package) elif fname.endswith('.py') and not fname.startswith('.'): + if self.shouldExclude(fullname): + continue self.addModule(fullname, package) + def shouldExclude(self, name): + '''Return True if this name is excluded''' + basename = os.path.basename(name) + for exclude in self.options.exclude: + if exclude.match(basename): + return True + return False + def handleDuplicate(self, obj): '''This is called when we see two objects with the same .fullName(), for example: