Add callback on plugin load failure
I have seen a few cases where import errors (distutils - I am looking at you) result in an extension not being available, but there is no indication why this is the case. We do configure logging, but this happens too late (as part of the 'cliff.app.App.run' call to execute a command, which calls osc-lib's 'configure_logging' but which happens long after we've tried to import our plugins) to be of any use. Instead, make use of a callback to make it more obvious. Change-Id: Id68b06161e445b79fe43f463e06cda3c4771ef02 Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
This commit is contained in:
parent
37a22cf84c
commit
aa88db9448
@ -158,10 +158,22 @@ class ClientManager(clientmanager.ClientManager):
|
||||
# Plugin Support
|
||||
|
||||
|
||||
def _on_load_failure_callback(
|
||||
manager: stevedore.ExtensionManager,
|
||||
ep: importlib.metadata.EntryPoint,
|
||||
err: Exception,
|
||||
) -> None:
|
||||
sys.stderr.write(
|
||||
f"WARNING: Failed to import plugin {ep.group}:{ep.name}: {err}.\n"
|
||||
)
|
||||
|
||||
|
||||
def get_plugin_modules(group):
|
||||
"""Find plugin entry points"""
|
||||
mod_list = []
|
||||
mgr = stevedore.ExtensionManager(group)
|
||||
mgr = stevedore.ExtensionManager(
|
||||
group, on_load_failure_callback=_on_load_failure_callback
|
||||
)
|
||||
for ep in mgr:
|
||||
LOG.debug('Found plugin %s', ep.name)
|
||||
|
||||
@ -180,9 +192,8 @@ def get_plugin_modules(group):
|
||||
module = importlib.import_module(module_name)
|
||||
except Exception as err:
|
||||
sys.stderr.write(
|
||||
"WARNING: Failed to import plugin {}: {}.\n".format(
|
||||
ep.name, err
|
||||
)
|
||||
f"WARNING: Failed to import plugin {ep.group}:{ep.name}: "
|
||||
f"{err}.\n"
|
||||
)
|
||||
continue
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user