From dc2b949225c290d6734dcc278c229661faf690d7 Mon Sep 17 00:00:00 2001 From: Ferdinand Thiessen Date: Sun, 31 Jul 2022 19:06:55 +0200 Subject: [PATCH] [cli] Fix exporting of plugin interfaces Signed-off-by: Ferdinand Thiessen --- flaschengeist/cli/export_cmd.py | 16 ++++++++++++---- flaschengeist/cli/plugin_cmd.py | 4 +++- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/flaschengeist/cli/export_cmd.py b/flaschengeist/cli/export_cmd.py index 6f93c70..2131f7b 100644 --- a/flaschengeist/cli/export_cmd.py +++ b/flaschengeist/cli/export_cmd.py @@ -1,4 +1,5 @@ import click +from importlib_metadata import entry_points @click.command() @@ -8,14 +9,21 @@ import click @click.option("--no-core", help="Skip models / types from flaschengeist core", is_flag=True) def export(namespace, output, no_core, plugin): from flaschengeist import logger, models - from flaschengeist.app import get_plugins from .InterfaceGenerator import InterfaceGenerator gen = InterfaceGenerator(namespace, output, logger) if not no_core: gen.run(models) if plugin: - for plugin_class in get_plugins(): - if (len(plugin) == 0 or plugin_class.id in plugin) and plugin_class.models is not None: - gen.run(plugin_class.models) + for entry_point in entry_points(group="flaschengeist.plugins"): + if len(plugin) == 0 or entry_point.name in plugin: + try: + plugin = entry_point.load() + gen.run(plugin.models) + except: + logger.error( + f"Plugin {entry_point.name} could not be loaded due to an error.", + exc_info=True, + ) + continue gen.write() diff --git a/flaschengeist/cli/plugin_cmd.py b/flaschengeist/cli/plugin_cmd.py index c2b5274..4a34cc6 100644 --- a/flaschengeist/cli/plugin_cmd.py +++ b/flaschengeist/cli/plugin_cmd.py @@ -97,7 +97,9 @@ def ls(enabled, no_header): return p.version plugins = entry_points(group="flaschengeist.plugins") - enabled_plugins = [key for key, value in config.items() if "enabled" in value and value["enabled"]] + [config["FLASCHENGEIST"]["auth"]] + enabled_plugins = [key for key, value in config.items() if "enabled" in value and value["enabled"]] + [ + config["FLASCHENGEIST"]["auth"] + ] loaded_plugins = current_app.config["FG_PLUGINS"].keys() if not no_header: