560
560
def load_module(self, fullname):
561
561
"""Load a plugin from a specific directory."""
562
562
# We are called only for specific paths
563
plugin_dir = self.specific_paths[fullname]
565
maybe_package = False
566
for p in os.listdir(plugin_dir):
567
if os.path.isdir(osutils.pathjoin(plugin_dir, p)):
568
# We're searching for files only and don't want submodules to
569
# be recognized as plugins (they are submodules inside the
573
suffix, mode, kind) = _find_plugin_module(plugin_dir, p)
575
candidate = (name, path, suffix, mode, kind)
576
if kind == imp.PY_SOURCE:
577
# We favour imp.PY_SOURCE (which will use the compiled
578
# version if available) over imp.PY_COMPILED (which is used
579
# only if the source is not available)
581
if candidate is None:
563
plugin_path = self.specific_paths[fullname]
566
if os.path.isdir(plugin_path):
567
for suffix, mode, kind in imp.get_suffixes():
568
if kind not in (imp.PY_SOURCE, imp.PY_COMPILED):
569
# We don't recognize compiled modules (.so, .dll, etc)
571
init_path = osutils.pathjoin(plugin_path, '__init__' + suffix)
572
if os.path.isfile(init_path):
573
loading_path = init_path
577
for suffix, mode, kind in imp.get_suffixes():
578
if plugin_path.endswith(suffix):
579
loading_path = plugin_path
581
if loading_path is None:
582
582
raise ImportError('%s cannot be loaded from %s'
583
% (fullname, plugin_dir))
583
% (fullname, plugin_path))
584
f = open(loading_path, mode)
586
mod = imp.load_module(fullname, f, path, (suffix, mode, kind))
587
# The plugin can contain modules, so be ready
588
mod.__path__ = [plugin_dir]
586
mod = imp.load_module(fullname, f, loading_path,
587
(suffix, mode, kind))
589
# The plugin can contain modules, so be ready
590
mod.__path__ = [plugin_path]
589
591
mod.__package__ = fullname