mirror of
https://github.com/getpelican/pelican.git
synced 2025-10-15 20:28:56 +02:00
Merge pull request #2818 from shniubobo/issue-2817
Fix plugins running twice in autoreload mode
This commit is contained in:
commit
c345268de6
2 changed files with 14 additions and 0 deletions
|
|
@ -53,6 +53,9 @@ def load_legacy_plugin(plugin, plugin_paths):
|
||||||
if spec is None:
|
if spec is None:
|
||||||
raise ImportError('Cannot import plugin `{}`'.format(plugin))
|
raise ImportError('Cannot import plugin `{}`'.format(plugin))
|
||||||
else:
|
else:
|
||||||
|
# Avoid loading the same plugin twice
|
||||||
|
if spec.name in sys.modules:
|
||||||
|
return sys.modules[spec.name]
|
||||||
# create module object from spec
|
# create module object from spec
|
||||||
mod = importlib.util.module_from_spec(spec)
|
mod = importlib.util.module_from_spec(spec)
|
||||||
# place it into sys.modules cache
|
# place it into sys.modules cache
|
||||||
|
|
|
||||||
|
|
@ -131,6 +131,17 @@ class PluginTest(unittest.TestCase):
|
||||||
'normal subpackage plugin'},
|
'normal subpackage plugin'},
|
||||||
get_plugin_names(plugins))
|
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
|
# namespace plugin short
|
||||||
SETTINGS = {
|
SETTINGS = {
|
||||||
'PLUGINS': ['ns_plugin']
|
'PLUGINS': ['ns_plugin']
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue