22
22
# commands, import bzrlib.commands and add your new command to the
23
23
# plugin_cmds variable.
27
from bzrlib.osutils import config_dir
28
DEFAULT_PLUGIN_PATH = os.path.join(config_dir(), 'plugins')
29
from sets import Set as set
30
from bzrlib.trace import log_error
34
33
def load_plugins():
36
Find all python plugins and load them.
38
Loading a plugin means importing it into the python interpreter.
39
The plugin is expected to make calls to register commands when
40
it's loaded (or perhaps access other hooks in future.)
42
A list of plugs is stored in bzrlib.plugin.all_plugins for future
45
The environment variable BZR_PLUGIN_PATH is considered a delimited
46
set of paths to look through. Each entry is searched for *.py
47
files (and whatever other extensions are used in the platform,
51
global all_plugins, _loaded
53
# People can make sure plugins are loaded, they just won't be twice
55
#raise BzrError("plugins already initialized")
60
from bzrlib.trace import log_error, mutter, log_exception
61
from bzrlib.errors import BzrError
62
from bzrlib import plugins
64
dirs = os.environ.get('BZR_PLUGIN_PATH', DEFAULT_PLUGIN_PATH).split(":")
65
dirs.insert(0, os.path.dirname(plugins.__file__))
34
"""Find all python files which are plugins, and load them
36
The environment variable BZR_PLUGIN_PATH is considered a delimited set of
37
paths to look through. Each entry is searched for *.py files (and whatever
38
other extensions are used in the platform, such as *.pyd).
40
bzrpath = os.environ.get('BZR_PLUGIN_PATH', os.path.expanduser('~/.bzr/plugins'))
67
42
# The problem with imp.get_suffixes() is that it doesn't include
68
43
# .pyo which is technically valid
72
47
suffixes = imp.get_suffixes()
73
48
suffixes.append(('.pyo', 'rb', imp.PY_COMPILED))
74
49
package_entries = ['__init__.py', '__init__.pyc', '__init__.pyo']
76
# going through them one by one allows different plugins with the same
50
for d in bzrpath.split(os.pathsep):
51
# going trough them one by one allows different plugins with the same
77
52
# filename in different directories in the path
78
mutter('looking for plugins in %s' % d)
81
55
plugin_names = set()
108
81
for name in plugin_names:
110
83
plugin_info = imp.find_module(name, [d])
111
mutter('load plugin %r' % (plugin_info,))
113
85
plugin = imp.load_module('bzrlib.plugin.' + name,
115
all_plugins.append(plugin)
117
88
if plugin_info[0] is not None:
118
89
plugin_info[0].close()
119
90
except Exception, e:
120
log_error('Unable to load plugin %r from %r' % (name, d))
91
log_error('Unable to load plugin: %r from %r\n%s' % (name, d, e))