Mercurial > piecrust2
diff piecrust/plugins/base.py @ 999:46025a1b5434
plugins: Support multiple customizable plugins directories.
Also add support for specifying the theme directory in some customizable paths.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Tue, 21 Nov 2017 09:54:56 -0800 |
parents | 8f8bbb2e70e1 |
children | 2e5c5d33d62c |
line wrap: on
line diff
--- a/piecrust/plugins/base.py Tue Nov 21 09:54:00 2017 -0800 +++ b/piecrust/plugins/base.py Tue Nov 21 09:54:56 2017 -0800 @@ -117,7 +117,8 @@ if to_install: for name in to_install: plugin = self._loadPlugin(name) - self._plugins.append(plugin) + if plugin is not None: + self._plugins.append(plugin) for plugin in self._plugins: plugin.initialize(self.app) @@ -131,18 +132,20 @@ mod = None if mod is None: - # Import as a loose Python file from the plugins dir. - pfile = os.path.join(self.app.plugins_dir, plugin_name + '.py') - if os.path.isfile(pfile): - spec = importlib.util.spec_from_file_location(plugin_name, - pfile) - mod = importlib.util.module_from_spec(spec) - spec.loader.exec_module(mod) - sys.modules[mod_name] = mod + # Import as a loose Python file from the plugins dirs. + for plugins_dir in self.app.plugins_dirs: + pfile = os.path.join(plugins_dir, plugin_name + '.py') + if os.path.isfile(pfile): + spec = importlib.util.spec_from_file_location(plugin_name, + pfile) + mod = importlib.util.module_from_spec(spec) + spec.loader.exec_module(mod) + sys.modules[mod_name] = mod + break if mod is None: logger.error("Failed to load plugin '%s'." % plugin_name) - logger.error(ex) + logger.error("Looking in: %s" % self.app.plugins_dirs) return plugin_class = getattr(mod, '__piecrust_plugin__', None)