mirror of
https://github.com/getpelican/pelican.git
synced 2025-10-15 20:28:56 +02:00
.
This commit is contained in:
parent
242fe10404
commit
b880bfadaa
1 changed files with 21 additions and 20 deletions
|
|
@ -53,27 +53,28 @@ def load_legacy_plugin(plugin, plugin_paths):
|
||||||
spec = importlib.util.find_spec(plugin)
|
spec = importlib.util.find_spec(plugin)
|
||||||
if spec is None:
|
if spec is None:
|
||||||
raise ImportError('Cannot import plugin `{}`'.format(plugin))
|
raise ImportError('Cannot import plugin `{}`'.format(plugin))
|
||||||
# Avoid loading the same plugin twice
|
else:
|
||||||
if spec.name in sys.modules:
|
# Avoid loading the same plugin twice
|
||||||
return sys.modules[spec.name]
|
if spec.name in sys.modules:
|
||||||
# create module object from spec
|
return sys.modules[spec.name]
|
||||||
mod = importlib.util.module_from_spec(spec)
|
# create module object from spec
|
||||||
# place it into sys.modules cache
|
mod = importlib.util.module_from_spec(spec)
|
||||||
# necessary if module imports itself at some point (e.g. packages)
|
# place it into sys.modules cache
|
||||||
sys.modules[spec.name] = mod
|
# necessary if module imports itself at some point (e.g. packages)
|
||||||
try:
|
sys.modules[spec.name] = mod
|
||||||
# try to execute it inside module object
|
|
||||||
spec.loader.exec_module(mod)
|
|
||||||
except Exception: # problem with import
|
|
||||||
try:
|
try:
|
||||||
# remove module from sys.modules since it can't be loaded
|
# try to execute it inside module object
|
||||||
del sys.modules[spec.name]
|
spec.loader.exec_module(mod)
|
||||||
except KeyError:
|
except Exception: # problem with import
|
||||||
pass
|
try:
|
||||||
raise
|
# 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
|
# if all went well, we have the plugin module
|
||||||
return mod
|
return mod
|
||||||
|
|
||||||
|
|
||||||
def load_plugins(settings):
|
def load_plugins(settings):
|
||||||
|
|
@ -121,4 +122,4 @@ def get_plugin_name(plugin):
|
||||||
if inspect.ismodule(plugin):
|
if inspect.ismodule(plugin):
|
||||||
return plugin.__name__
|
return plugin.__name__
|
||||||
|
|
||||||
return type(plugin).__qualname__
|
return type(plugin).__qualname__
|
||||||
Loading…
Add table
Add a link
Reference in a new issue