42
42
from bzrlib import (
46
from bzrlib import plugins as _mod_plugins
49
from bzrlib.symbol_versioning import deprecated_function, zero_ninetyone
49
50
from bzrlib.trace import mutter, warning, log_exception_quietly
60
61
return DEFAULT_PLUGIN_PATH
64
@deprecated_function(zero_ninetyone)
64
66
"""Return a dictionary of the plugins."""
66
for name, plugin in plugins.__dict__.items():
67
if isinstance(plugin, types.ModuleType):
67
return dict((name, plugin.module) for name, plugin in plugins().items())
72
70
def disable_plugins():
80
def _strip_trailing_sep(path):
81
return path.rstrip("\\/")
83
83
def set_plugins_path():
84
84
"""Set the path for plugins to be loaded from."""
85
85
path = os.environ.get('BZR_PLUGIN_PATH',
86
86
get_default_plugin_path()).split(os.pathsep)
87
# Get rid of trailing slashes, since Python can't handle them when
88
# it tries to import modules.
89
path = map(_strip_trailing_sep, path)
87
90
# search the plugin path before the bzrlib installed dir
88
path.append(os.path.dirname(plugins.__file__))
89
plugins.__path__ = path
91
path.append(os.path.dirname(_mod_plugins.__file__))
92
_mod_plugins.__path__ = path
124
127
The python module path for bzrlib.plugins will be modified to be 'dirs'.
126
plugins.__path__ = dirs
129
# We need to strip the trailing separators here as well as in the
130
# set_plugins_path function because calling code can pass anything in to
131
# this function, and since it sets plugins.__path__, it should set it to
132
# something that will be valid for Python to use (in case people try to
133
# run "import bzrlib.plugins.PLUGINNAME" after calling this function).
134
_mod_plugins.__path__ = map(_strip_trailing_sep, dirs)
172
if getattr(plugins, f, None):
180
if getattr(_mod_plugins, f, None):
173
181
mutter('Plugin name %s already loaded', f)
175
183
# mutter('add plugin name %s', f)
254
262
if not plugin_name:
256
if getattr(plugins, plugin_name, None):
264
if getattr(_mod_plugins, plugin_name, None):
257
265
mutter('Plugin name %s already loaded', plugin_name)
269
277
log_exception_quietly()
281
"""Return a dictionary of the plugins.
283
Each item in the dictionary is a PlugIn object.
286
for name, plugin in _mod_plugins.__dict__.items():
287
if isinstance(plugin, types.ModuleType):
288
result[name] = PlugIn(name, plugin)
272
292
class PluginsHelpIndex(object):
273
293
"""A help index that returns help topics for plugins."""
335
355
def get_help_topic(self):
336
356
"""Return the modules help topic - its __name__ after bzrlib.plugins.."""
337
357
return self.module.__name__[len('bzrlib.plugins.'):]
360
class PlugIn(object):
361
"""The bzrlib representation of a plugin.
363
The PlugIn object provides a way to manipulate a given plugin module.
366
def __init__(self, name, module):
367
"""Construct a plugin for module."""
372
"""Get the path that this plugin was loaded from."""
373
if getattr(self.module, '__path__', None) is not None:
374
return os.path.abspath(self.module.__path__[0])
375
elif getattr(self.module, '__file__', None) is not None:
376
return os.path.abspath(self.module.__file__)
378
return repr(self.module)
381
return "<%s.%s object at %s, name=%s, module=%s>" % (
382
self.__class__.__module__, self.__class__.__name__, id(self),
383
self.name, self.module)
387
def test_suite(self):
388
"""Return the plugin's test suite."""
389
if getattr(self.module, 'test_suite', None) is not None:
390
return self.module.test_suite()
394
def version_info(self):
395
"""Return the plugin's version_tuple or None if unknown."""
396
version_info = getattr(self.module, 'version_info', None)
397
if version_info is not None and len(version_info) == 3:
398
version_info = tuple(version_info) + ('final', 0)
401
def _get__version__(self):
402
version_info = self.version_info()
403
if version_info is None:
405
if version_info[3] == 'final':
406
version_string = '%d.%d.%d' % version_info[:3]
408
version_string = '%d.%d.%d%s%d' % version_info
409
return version_string
411
__version__ = property(_get__version__)