85
def describe_plugins(show_paths=False):
86
"""Generate text description of plugins.
88
Includes both those that have loaded, and those that failed to
91
:param show_paths: If true,
92
:returns: Iterator of text lines (including newlines.)
94
from inspect import getdoc
95
loaded_plugins = plugins()
96
all_names = sorted(list(set(
97
loaded_plugins.keys() + plugin_warnings.keys())))
98
for name in all_names:
99
if name in loaded_plugins:
100
plugin = loaded_plugins[name]
101
version = plugin.__version__
102
if version == 'unknown':
104
yield '%s %s\n' % (name, version)
105
d = getdoc(plugin.module)
107
doc = d.split('\n')[0]
109
doc = '(no description)'
110
yield (" %s\n" % doc)
112
yield (" %s\n" % plugin.path())
115
yield "%s (failed to load)\n" % name
116
if name in plugin_warnings:
117
for line in plugin_warnings[name]:
118
yield " ** " + line + '\n'
80
122
def _strip_trailing_sep(path):
81
123
return path.rstrip("\\/")
126
def _get_specific_plugin_paths(paths):
127
"""Returns the plugin paths from a string describing the associations.
129
:param paths: A string describing the paths associated with the plugins.
131
:returns: A list of (plugin name, path) tuples.
133
For example, if paths is my_plugin@/test/my-test:her_plugin@/production/her,
134
[('my_plugin', '/test/my-test'), ('her_plugin', '/production/her')]
137
Note that ':' in the example above depends on the os.
142
for spec in paths.split(os.pathsep):
144
name, path = spec.split('@')
146
raise errors.BzrCommandError(
147
'"%s" is not a valid <plugin_name>@<plugin_path> description '
149
specs.append((name, path))
84
153
def set_plugins_path(path=None):
85
154
"""Set the path for plugins to be loaded from.
98
167
for name in disabled_plugins.split(os.pathsep):
99
168
PluginImporter.blacklist.add('bzrlib.plugins.' + name)
100
169
# Set up a the specific paths for plugins
101
specific_plugins = os.environ.get('BZR_PLUGINS_AT', None)
102
if specific_plugins is not None:
103
for spec in specific_plugins.split(os.pathsep):
104
plugin_name, plugin_path = spec.split('@')
170
for plugin_name, plugin_path in _get_specific_plugin_paths(os.environ.get(
171
'BZR_PLUGINS_AT', None)):
105
172
PluginImporter.specific_paths[
106
173
'bzrlib.plugins.%s' % plugin_name] = plugin_path
302
369
return None, None, (None, None, None)
372
def record_plugin_warning(plugin_name, warning_message):
373
trace.mutter(warning_message)
374
plugin_warnings.setdefault(plugin_name, []).append(warning_message)
305
377
def _load_plugin_module(name, dir):
306
378
"""Load plugin name from dir.
315
387
except KeyboardInterrupt:
317
389
except errors.IncompatibleAPI, e:
318
trace.warning("Unable to load plugin %r. It requested API version "
391
"Unable to load plugin %r. It requested API version "
319
392
"%s of module %s but the minimum exported version is %s, and "
320
393
"the maximum is %s" %
321
394
(name, e.wanted, e.api, e.minimum, e.current))
395
record_plugin_warning(name, warning_message)
322
396
except Exception, e:
323
397
trace.warning("%s" % e)
324
398
if re.search('\.|-| ', name):
329
403
"file path isn't a valid module name; try renaming "
330
404
"it to %r." % (name, dir, sanitised_name))
332
trace.warning('Unable to load plugin %r from %r' % (name, dir))
406
record_plugin_warning(
408
'Unable to load plugin %r from %r' % (name, dir))
333
409
trace.log_exception_quietly()
334
410
if 'error' in debug.debug_flags:
335
411
trace.print_exception(sys.exc_info(), sys.stderr)
562
638
# We are called only for specific paths
563
639
plugin_path = self.specific_paths[fullname]
564
640
loading_path = None
566
641
if os.path.isdir(plugin_path):
567
642
for suffix, mode, kind in imp.get_suffixes():
568
643
if kind not in (imp.PY_SOURCE, imp.PY_COMPILED):
571
646
init_path = osutils.pathjoin(plugin_path, '__init__' + suffix)
572
647
if os.path.isfile(init_path):
573
loading_path = init_path
648
# We've got a module here and load_module needs specific
650
loading_path = plugin_path
653
kind = imp.PKG_DIRECTORY
577
656
for suffix, mode, kind in imp.get_suffixes():
581
660
if loading_path is None:
582
661
raise ImportError('%s cannot be loaded from %s'
583
662
% (fullname, plugin_path))
584
f = open(loading_path, mode)
663
if kind is imp.PKG_DIRECTORY:
666
f = open(loading_path, mode)
586
668
mod = imp.load_module(fullname, f, loading_path,
587
669
(suffix, mode, kind))
589
# The plugin can contain modules, so be ready
590
mod.__path__ = [plugin_path]
591
670
mod.__package__ = fullname
597
677
# Install a dedicated importer for plugins requiring special handling