mirror of
https://github.com/getpelican/pelican.git
synced 2025-10-15 20:28:56 +02:00
Fix legacy plugin loading
This commit is contained in:
parent
f610801ee8
commit
46e1ec4f99
3 changed files with 21 additions and 1 deletions
|
|
@ -3,6 +3,7 @@ import importlib.machinery
|
||||||
import importlib.util
|
import importlib.util
|
||||||
import logging
|
import logging
|
||||||
import pkgutil
|
import pkgutil
|
||||||
|
import sys
|
||||||
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
@ -47,8 +48,23 @@ 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:
|
||||||
|
# create module object from spec
|
||||||
mod = importlib.util.module_from_spec(spec)
|
mod = importlib.util.module_from_spec(spec)
|
||||||
spec.loader.exec_module(mod)
|
# place it into sys.modules cache
|
||||||
|
# necessary if module imports itself at some point (e.g. packages)
|
||||||
|
sys.modules[spec.name] = mod
|
||||||
|
try:
|
||||||
|
# try to execute it inside module object
|
||||||
|
spec.loader.exec_module(mod)
|
||||||
|
except Exception: # problem with import
|
||||||
|
try:
|
||||||
|
# remove module from sys.modules since it can't be loaded
|
||||||
|
del sys.modules[spec.name]
|
||||||
|
except KeyError:
|
||||||
|
pass
|
||||||
|
raise
|
||||||
|
|
||||||
|
# if all went well, we have the plugin module
|
||||||
return mod
|
return mod
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
from .submodule import noop # noqa: F401
|
||||||
|
|
||||||
NAME = 'normal plugin'
|
NAME = 'normal plugin'
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,2 @@
|
||||||
|
def noop():
|
||||||
|
pass
|
||||||
Loading…
Add table
Add a link
Reference in a new issue