/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/plugin.py

Cleanup docs.

Show diffs side-by-side

added added

removed removed

Lines of Context:
244
244
 
245
245
    The python module path for bzrlib.plugins will be modified to be 'dirs'.
246
246
    """
 
247
    # Explicitly load the plugins with a specific path
247
248
    for fullname, path in PluginImporter.specific_paths.iteritems():
248
249
        name = fullname[len('bzrlib.plugins.'):]
249
 
        _load_plugin_module(name, path) # XXX: path *contains* test_foo
 
250
        _load_plugin_module(name, path)
250
251
 
251
252
    # We need to strip the trailing separators here as well as in the
252
253
    # set_plugins_path function because calling code can pass anything in to
270
271
def _find_plugin_module(dir, name):
271
272
    """Check if there is a valid python module that can be loaded as a plugin.
272
273
 
 
274
    :param dir: The directory where the search is performed.
273
275
    :param path: An existing file path, either a python file or a package
274
276
        directory.
275
277
 
301
303
 
302
304
 
303
305
def _load_plugin_module(name, dir):
 
306
    """Load plugine name from dir.
 
307
 
 
308
    :param name: The plugin name in the bzrlib.plugins namespace.
 
309
    :param dir: The directory the plugin is loaded from for error messages.
 
310
    """
304
311
    if ('bzrlib.plugins.%s' % name) in PluginImporter.blacklist:
305
312
        return
306
313
    try:
519
526
 
520
527
 
521
528
class _PluginImporter(object):
 
529
    """An importer tailored to bzr specific needs.
 
530
 
 
531
    This is a singleton that takes care of:
 
532
    - disabled plugins specified in 'blacklist',
 
533
    - plugins that needs to be loaded from specific directories.
 
534
    """
522
535
 
523
536
    def __init__(self):
524
537
        self.reset()
528
541
        self.specific_paths = {}
529
542
 
530
543
    def find_module(self, fullname, parent_path=None):
 
544
        """Search a plugin module.
 
545
 
 
546
        Disabled plugins raise an import error, plugins with specific paths
 
547
        returns a specific loader.
 
548
 
 
549
        :return: None if the plugin doesn't need special handling, self
 
550
            otherwise.
 
551
        """
531
552
        if not fullname.startswith('bzrlib.plugins.'):
532
553
            return None
533
554
        if fullname in self.blacklist:
537
558
        return None
538
559
 
539
560
    def load_module(self, fullname):
 
561
        """Load a plugin from a specific directory."""
540
562
        # We are called only for specific paths
541
563
        plugin_dir = self.specific_paths[fullname]
542
564
        candidate = None
572
594
            f.close()
573
595
 
574
596
 
 
597
# Install a dedicated importer for plugins requiring special handling
575
598
PluginImporter = _PluginImporter()
576
599
sys.meta_path.append(PluginImporter)