summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJustin Mayer <entroP@gmail.com>2020-11-02 12:40:13 +0100
committerGitHub <noreply@github.com>2020-11-02 12:40:13 +0100
commitc345268de6b754d31dbae67d0fc23efc0db5e6fe (patch)
tree0e3fe3f7ce8e21f23b5864975ed9755c408c0b5e
parente4d9c41a77b45cb7ff6b8d1732623990adf65931 (diff)
parent587e1a4ad89da2be46368baafb4f00b3b3d0c64a (diff)
downloadpelican-c345268de6b754d31dbae67d0fc23efc0db5e6fe.tar.gz
Merge pull request #2818 from shniubobo/issue-2817
Fix plugins running twice in autoreload mode
-rw-r--r--pelican/plugins/_utils.py3
-rw-r--r--pelican/tests/test_plugins.py11
2 files changed, 14 insertions, 0 deletions
diff --git a/pelican/plugins/_utils.py b/pelican/plugins/_utils.py
index 4e6ec3c5..ffe32799 100644
--- a/pelican/plugins/_utils.py
+++ b/pelican/plugins/_utils.py
@@ -53,6 +53,9 @@ def load_legacy_plugin(plugin, plugin_paths):
if spec is None:
raise ImportError('Cannot import plugin `{}`'.format(plugin))
else:
+ # Avoid loading the same plugin twice
+ if spec.name in sys.modules:
+ return sys.modules[spec.name]
# create module object from spec
mod = importlib.util.module_from_spec(spec)
# place it into sys.modules cache
diff --git a/pelican/tests/test_plugins.py b/pelican/tests/test_plugins.py
index 06940884..29729539 100644
--- a/pelican/tests/test_plugins.py
+++ b/pelican/tests/test_plugins.py
@@ -131,6 +131,17 @@ class PluginTest(unittest.TestCase):
'normal subpackage plugin'},
get_plugin_names(plugins))
+ # ensure normal plugins are loaded only once
+ SETTINGS = {
+ 'PLUGINS': ['normal_plugin'],
+ 'PLUGIN_PATHS': [self._NORMAL_PLUGIN_FOLDER],
+ }
+ plugins = load_plugins(SETTINGS)
+ for plugin in load_plugins(SETTINGS):
+ # The second load_plugins() should return the same plugin
+ # objects as the first one
+ self.assertIn(plugin, plugins)
+
# namespace plugin short
SETTINGS = {
'PLUGINS': ['ns_plugin']