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'
122
80
def _strip_trailing_sep(path):
123
81
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))
153
84
def set_plugins_path(path=None):
154
85
"""Set the path for plugins to be loaded from.
167
98
for name in disabled_plugins.split(os.pathsep):
168
99
PluginImporter.blacklist.add('bzrlib.plugins.' + name)
169
100
# Set up a the specific paths for plugins
170
for plugin_name, plugin_path in _get_specific_plugin_paths(os.environ.get(
171
'BZR_PLUGINS_AT', None)):
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('@')
172
105
PluginImporter.specific_paths[
173
106
'bzrlib.plugins.%s' % plugin_name] = plugin_path
369
302
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)
377
305
def _load_plugin_module(name, dir):
378
306
"""Load plugin name from dir.
387
315
except KeyboardInterrupt:
389
317
except errors.IncompatibleAPI, e:
391
"Unable to load plugin %r. It requested API version "
318
trace.warning("Unable to load plugin %r. It requested API version "
392
319
"%s of module %s but the minimum exported version is %s, and "
393
320
"the maximum is %s" %
394
321
(name, e.wanted, e.api, e.minimum, e.current))
395
record_plugin_warning(name, warning_message)
396
322
except Exception, e:
397
323
trace.warning("%s" % e)
398
324
if re.search('\.|-| ', name):
403
329
"file path isn't a valid module name; try renaming "
404
330
"it to %r." % (name, dir, sanitised_name))
406
record_plugin_warning(
408
'Unable to load plugin %r from %r' % (name, dir))
332
trace.warning('Unable to load plugin %r from %r' % (name, dir))
409
333
trace.log_exception_quietly()
410
334
if 'error' in debug.debug_flags:
411
335
trace.print_exception(sys.exc_info(), sys.stderr)
638
562
# We are called only for specific paths
639
563
plugin_path = self.specific_paths[fullname]
640
564
loading_path = None
641
566
if os.path.isdir(plugin_path):
642
567
for suffix, mode, kind in imp.get_suffixes():
643
568
if kind not in (imp.PY_SOURCE, imp.PY_COMPILED):
646
571
init_path = osutils.pathjoin(plugin_path, '__init__' + suffix)
647
572
if os.path.isfile(init_path):
648
# We've got a module here and load_module needs specific
650
loading_path = plugin_path
653
kind = imp.PKG_DIRECTORY
573
loading_path = init_path
656
577
for suffix, mode, kind in imp.get_suffixes():
660
581
if loading_path is None:
661
582
raise ImportError('%s cannot be loaded from %s'
662
583
% (fullname, plugin_path))
663
if kind is imp.PKG_DIRECTORY:
666
f = open(loading_path, mode)
584
f = open(loading_path, mode)
668
586
mod = imp.load_module(fullname, f, loading_path,
669
587
(suffix, mode, kind))
589
# The plugin can contain modules, so be ready
590
mod.__path__ = [plugin_path]
670
591
mod.__package__ = fullname
677
597
# Install a dedicated importer for plugins requiring special handling