~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/plugin.py

  • Committer: Tarmac
  • Author(s): Vincent Ladeuil
  • Date: 2017-01-30 14:42:05 UTC
  • mfrom: (6620.1.1 trunk)
  • Revision ID: tarmac-20170130144205-r8fh2xpmiuxyozpv
Merge  2.7 into trunk including fix for bug #1657238 [r=vila]

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
 
 
18
17
"""bzr python plugin support.
19
18
 
20
19
When load_plugins() is invoked, any python module in any directory in
30
29
called.
31
30
"""
32
31
 
 
32
from __future__ import absolute_import
 
33
 
33
34
import os
34
35
import sys
35
36
 
36
37
from bzrlib import osutils
37
38
 
38
39
from bzrlib.lazy_import import lazy_import
39
 
 
40
40
lazy_import(globals(), """
41
41
import imp
42
42
import re
49
49
    errors,
50
50
    trace,
51
51
    )
 
52
from bzrlib.i18n import gettext
52
53
from bzrlib import plugins as _mod_plugins
53
54
""")
54
55
 
55
 
from bzrlib.symbol_versioning import (
56
 
    deprecated_function,
57
 
    deprecated_in,
58
 
    )
59
 
 
60
56
 
61
57
DEFAULT_PLUGIN_PATH = None
62
58
_loaded = False
143
139
        try:
144
140
            name, path = spec.split('@')
145
141
        except ValueError:
146
 
            raise errors.BzrCommandError(
147
 
                '"%s" is not a valid <plugin_name>@<plugin_path> description '
 
142
            raise errors.BzrCommandError(gettext(
 
143
                '"%s" is not a valid <plugin_name>@<plugin_path> description ')
148
144
                % spec)
149
145
        specs.append((name, path))
150
146
    return specs
278
274
    """Load bzrlib plugins.
279
275
 
280
276
    The environment variable BZR_PLUGIN_PATH is considered a delimited
281
 
    set of paths to look through. Each entry is searched for *.py
 
277
    set of paths to look through. Each entry is searched for `*.py`
282
278
    files (and whatever other extensions are used in the platform,
283
 
    such as *.pyd).
 
279
    such as `*.pyd`).
284
280
 
285
281
    load_from_path() provides the underlying mechanism and is called with
286
282
    the default directory list to provide the normal behaviour.
451
447
    return result
452
448
 
453
449
 
 
450
def format_concise_plugin_list():
 
451
    """Return a string holding a concise list of plugins and their version.
 
452
    """
 
453
    items = []
 
454
    for name, a_plugin in sorted(plugins().items()):
 
455
        items.append("%s[%s]" %
 
456
            (name, a_plugin.__version__))
 
457
    return ', '.join(items)
 
458
 
 
459
 
 
460
 
454
461
class PluginsHelpIndex(object):
455
462
    """A help index that returns help topics for plugins."""
456
463
 
501
508
            result = self.module.__doc__
502
509
        if result[-1] != '\n':
503
510
            result += '\n'
504
 
        # there is code duplicated here and in bzrlib/help_topic.py's
505
 
        # matching Topic code. This should probably be factored in
506
 
        # to a helper function and a common base class.
507
 
        if additional_see_also is not None:
508
 
            see_also = sorted(set(additional_see_also))
509
 
        else:
510
 
            see_also = None
511
 
        if see_also:
512
 
            result += 'See also: '
513
 
            result += ', '.join(see_also)
514
 
            result += '\n'
 
511
        from bzrlib import help_topics
 
512
        result += help_topics._format_see_also(additional_see_also)
515
513
        return result
516
514
 
517
515
    def get_help_topic(self):
518
 
        """Return the modules help topic - its __name__ after bzrlib.plugins.."""
 
516
        """Return the module help topic: its basename."""
519
517
        return self.module.__name__[len('bzrlib.plugins.'):]
520
518
 
521
519
 
634
632
        return None
635
633
 
636
634
    def load_module(self, fullname):
637
 
        """Load a plugin from a specific directory."""
 
635
        """Load a plugin from a specific directory (or file)."""
638
636
        # We are called only for specific paths
639
637
        plugin_path = self.specific_paths[fullname]
640
638
        loading_path = None