From 43c1af3996444d678d41bd2192910cf00b970f55 Mon Sep 17 00:00:00 2001 From: miro Date: Sun, 5 Jan 2025 16:34:14 +0000 Subject: [PATCH] fix: modernize importlib remove the compat layer for old python versions, use stdlib directly --- ovos_plugin_manager/utils/__init__.py | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) diff --git a/ovos_plugin_manager/utils/__init__.py b/ovos_plugin_manager/utils/__init__.py index ceeeae20..a348ddf1 100644 --- a/ovos_plugin_manager/utils/__init__.py +++ b/ovos_plugin_manager/utils/__init__.py @@ -17,8 +17,8 @@ from threading import Event, Lock from typing import Optional import warnings -import pkg_resources from ovos_utils.log import LOG, log_deprecation, deprecated +from importlib.metadata import entry_points class PluginTypes(str, Enum): @@ -126,7 +126,7 @@ def find_plugins(plug_type: PluginTypes = None) -> dict: else: plugs = plug_type for plug in plugs: - for entry_point in _iter_entrypoints(plug): + for entry_point in entry_points(group=plug): try: entrypoints[entry_point.name] = entry_point.load() if entry_point.name not in entrypoints: @@ -143,21 +143,6 @@ def find_plugins(plug_type: PluginTypes = None) -> dict: find_plugins._errored = [] -def _iter_entrypoints(plug_type: Optional[str]): - """ - Return an iterator containing all entrypoints of the requested type - @param plug_type: entrypoint name to load - @return: iterator of all entrypoints - """ - 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: str, plug_type: Optional[PluginTypes] = None): """Load a specific plugin from a specific plugin type.