22
22
# commands, import bzrlib.commands and add your new command to the
23
23
# plugin_cmds variable.
29
from sets import Set as set # python2.3
30
from bzrlib.trace import log_error
33
26
DEFAULT_PLUGIN_PATH = '~/.bzr.conf/plugins'
36
31
def load_plugins():
37
"""Find all python files which are plugins, and load them
39
The environment variable BZR_PLUGIN_PATH is considered a delimited set of
40
paths to look through. Each entry is searched for *.py files (and whatever
41
other extensions are used in the platform, such as *.pyd).
33
Find all python plugins and load them.
35
Loading a plugin means importing it into the python interpreter.
36
The plugin is expected to make calls to register commands when
37
it's loaded (or perhaps access other hooks in future.)
39
A list of plugs is stored in bzrlib.plugin.all_plugins for future
42
The environment variable BZR_PLUGIN_PATH is considered a delimited
43
set of paths to look through. Each entry is searched for *.py
44
files (and whatever other extensions are used in the platform,
52
from sets import Set as set # python2.3
54
from bzrlib.trace import log_error, mutter, log_exception
55
from bzrlib.errors import BzrError
43
57
bzrpath = os.environ.get('BZR_PLUGIN_PATH')
45
59
bzrpath = os.path.expanduser(DEFAULT_PLUGIN_PATH)
63
raise BzrError("plugins already initialized")
47
65
# The problem with imp.get_suffixes() is that it doesn't include
48
66
# .pyo which is technically valid
49
67
# It also means that "testmodule.so" will show up as both test and testmodule
53
71
suffixes.append(('.pyo', 'rb', imp.PY_COMPILED))
54
72
package_entries = ['__init__.py', '__init__.pyc', '__init__.pyo']
55
73
for d in bzrpath.split(os.pathsep):
56
# going trough them one by one allows different plugins with the same
74
# going through them one by one allows different plugins with the same
57
75
# filename in different directories in the path
76
mutter('looking for plugins in %s' % d)
60
79
plugin_names = set()
86
106
for name in plugin_names:
88
108
plugin_info = imp.find_module(name, [d])
109
mutter('load plugin %r' % (plugin_info,))
90
111
plugin = imp.load_module('bzrlib.plugin.' + name,
113
all_plugins.append(plugin_info)
93
115
if plugin_info[0] is not None:
94
116
plugin_info[0].close()
95
117
except Exception, e:
96
log_error('Unable to load plugin: %r from %r\n%s' % (name, d, e))
118
log_error('Unable to load plugin %r from %r' % (name, d))