From 74c82b8c9ab7bb64f0fbb22e0c122c8672eb3bb8 Mon Sep 17 00:00:00 2001 From: JarbasAI <33701864+JarbasAl@users.noreply.github.com> Date: Thu, 2 Feb 2023 21:04:53 +0000 Subject: [PATCH] fix/entrypoint_loading (#117) this avoids issues with requirement versions mismatches in skills, this should be handled at install time not runtime solution taken from: https://github.com/click-contrib/click-plugins/issues/31 --- ovos_plugin_manager/utils/__init__.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/ovos_plugin_manager/utils/__init__.py b/ovos_plugin_manager/utils/__init__.py index b1860238..302fc385 100644 --- a/ovos_plugin_manager/utils/__init__.py +++ b/ovos_plugin_manager/utils/__init__.py @@ -82,14 +82,25 @@ def find_plugins(plug_type=None): else: plugs = plug_type for plug in plugs: - for entry_point in pkg_resources.iter_entry_points(plug): + for entry_point in _iter_entrypoints(plug): try: entrypoints[entry_point.name] = entry_point.load() + LOG.debug(f"Loaded plugin entry point {entry_point.name}") except Exception as e: LOG.exception(f"Failed to load plugin entry point {entry_point}") return entrypoints +def _iter_entrypoints(plug_type): + try: + from importlib_metadata import entry_points + for entry_point in entry_points(group=plug_type): + yield entry_point + except ImportError: + for entry_point in pkg_resources.iter_entry_points(plug_type): + yield entry_point + + def load_plugin(plug_name, plug_type=None): """Load a specific plugin from a specific plugin type.