From c386e29d0c21e17895eef545e1ba0936ccc9c30a Mon Sep 17 00:00:00 2001 From: Lonewolf Date: Sun, 2 Mar 2014 19:21:22 +0530 Subject: [PATCH] Ability to specify PLUGIN_PATH as list PLUGIN_PATH added to settings table --- docs/plugins.rst | 2 +- pelican/__init__.py | 3 ++- pelican/settings.py | 14 +++++++++++--- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/docs/plugins.rst b/docs/plugins.rst index c03b1251..9dddce70 100644 --- a/docs/plugins.rst +++ b/docs/plugins.rst @@ -24,7 +24,7 @@ If your plugins are not in an importable path, you can specify a ``PLUGIN_PATH`` in the settings. ``PLUGIN_PATH`` can be an absolute path or a path relative to the settings file:: - PLUGIN_PATH = "plugins" + PLUGIN_PATH = ["list", "of", plugins path"] PLUGINS = ["list", "of", "plugins"] Where to find plugins diff --git a/pelican/__init__.py b/pelican/__init__.py index 1ed98fc3..077859bb 100644 --- a/pelican/__init__.py +++ b/pelican/__init__.py @@ -65,7 +65,8 @@ class Pelican(object): self.plugins = [] logger.debug('Temporarily adding PLUGIN_PATH to system path') _sys_path = sys.path[:] - sys.path.insert(0, self.settings['PLUGIN_PATH']) + for pluginpath in self.settings['PLUGIN_PATH']: + sys.path.insert(0, pluginpath) for plugin in self.settings['PLUGINS']: # if it's a string, then import it if isinstance(plugin, six.string_types): diff --git a/pelican/settings.py b/pelican/settings.py index 7615c25c..7caffa61 100644 --- a/pelican/settings.py +++ b/pelican/settings.py @@ -112,7 +112,7 @@ DEFAULT_CONFIG = { 'ARTICLE_PERMALINK_STRUCTURE': '', 'TYPOGRIFY': False, 'SUMMARY_MAX_LENGTH': 50, - 'PLUGIN_PATH': '', + 'PLUGIN_PATH': [], 'PLUGINS': [], 'PYGMENTS_RST_OPTIONS': {}, 'TEMPLATE_PAGES': {}, @@ -135,13 +135,21 @@ def read_settings(path=None, override=None): if path: local_settings = get_settings_from_file(path) # Make the paths relative to the settings file - for p in ['PATH', 'OUTPUT_PATH', 'THEME', 'PLUGIN_PATH']: + for p in ['PATH', 'OUTPUT_PATH', 'THEME']: if p in local_settings and local_settings[p] is not None \ and not isabs(local_settings[p]): absp = os.path.abspath(os.path.normpath(os.path.join( os.path.dirname(path), local_settings[p]))) - if p not in ('THEME', 'PLUGIN_PATH') or os.path.exists(absp): + if p not in ('THEME') or os.path.exists(absp): local_settings[p] = absp + + if isinstance(local_settings['PLUGIN_PATH'], six.string_types): + logger.warning("Detected misconfiguration with %s setting ""(must be a list)" % 'PLUGIN_PATH') + local_settings['PLUGIN_PATH'] = [local_settings['PLUGIN_PATH']] + else: + if 'PLUGIN_PATH' in local_settings and local_settings['PLUGIN_PATH'] is not None: + local_settings['PLUGIN_PATH'] = [os.path.abspath(os.path.normpath(os.path.join(os.path.dirname(path), pluginpath))) + if not isabs(pluginpath) else pluginpath for pluginpath in local_settings['PLUGIN_PATH']] else: local_settings = copy.deepcopy(DEFAULT_CONFIG)