Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 24 additions & 32 deletions ovos_plugin_manager/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,38 +211,30 @@ def find_plugins(plug_type: PluginTypes = None) -> dict:

find_plugins._errored = []

# compat with older python versions
try:
from importlib_metadata import entry_points

def _iter_plugins(plug_type):
"""
Yields all entry points for the specified plugin group.

Parameters:
plug_type: The entry point group name to search for.

Yields:
Entry points belonging to the specified group.
"""
for entry_point in entry_points(group=plug_type):
yield entry_point
except ImportError:

import pkg_resources # deprecated in newer python versions

def _iter_plugins(plug_type):
"""
Yield all entry points for the specified plugin group using pkg_resources.

Parameters:
plug_type (str): The entry point group name to search for.

Yields:
EntryPoint: Each discovered entry point in the specified group.
"""
for entry_point in pkg_resources.iter_entry_points(plug_type):
yield entry_point
# stdlib importlib.metadata (Python 3.8+) covers this project's own
# `requires-python = ">=3.10"` -- the external importlib_metadata
# backport package and the pkg_resources fallback are both unnecessary
# now. Confirmed for real: a fresh venv without importlib_metadata
# installed fell through to pkg_resources, which itself raised
# ModuleNotFoundError -- setuptools no longer bundles pkg_resources by
# default in recent releases (it's slated for removal entirely). Using
# the stdlib module directly removes both failure modes at once, with
# no new dependency to declare.
from importlib.metadata import entry_points


def _iter_plugins(plug_type):
"""
Yields all entry points for the specified plugin group.

Parameters:
plug_type: The entry point group name to search for.

Yields:
Entry points belonging to the specified group.
"""
for entry_point in entry_points(group=plug_type):
yield entry_point


def _iter_entrypoints(plug_type: Union[str, PluginTypes]):
Expand Down
Loading