1
# Copyright (C) 2008 Canonical Ltd
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
# GNU General Public License for more details.
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
"""Custom module finder for entire package"""
25
class CustomModuleFinder(modulefinder.ModuleFinder):
26
"""Custom module finder for processing python packages,
27
e.g. bzr plugins packages.
29
:param path: list of directories to search for modules;
30
if not specified, python standard library only is used.
33
def __init__(self, path=None, debug=0, excludes=[], replace_paths=[]):
35
path = [os.path.join(sys.prefix, 'Lib')] # only python std lib
36
modulefinder.ModuleFinder.__init__(self, path, debug, excludes,
39
def run_package(self, package_path):
40
"""Recursively process each module in package with run_script method.
42
:param package_path: path to package directory.
44
stack = [package_path]
47
py = os.listdir(curdir)
49
full = os.path.join(curdir, i)
50
if os.path.isdir(full):
51
init = os.path.join(full, '__init__.py')
52
if os.path.isfile(init):
55
if not i.endswith('.py'):
57
if i == 'setup.py': # skip
62
"""Return 2-tuple: (list of packages, list of modules)"""
63
keys = self.modules.keys()
69
if not m.__file__: # skip builtins
73
elif key != '__main__':
78
if __name__ == '__main__':
81
mf = CustomModuleFinder()
82
mf.run_package(package)
84
packs, mods = mf.get_result()