frostfs-testlib/src/frostfs_testlib/plugins/__init__.py
Andrey Berezin f072f88673 [#127] Change service registration
Signed-off-by: Andrey Berezin <a.berezin@yadro.com>
2023-11-22 19:54:39 +03:00

32 lines
838 B
Python

from importlib.metadata import entry_points
from typing import Any
def load_plugin(plugin_group: str, name: str) -> Any:
"""Loads plugin using entry point specification.
Args:
plugin_group: Name of plugin group that contains the plugin.
name: Name of the plugin in the group.
Returns:
Plugin class if the plugin was found; otherwise returns None.
"""
plugins = entry_points(group=plugin_group)
if name not in plugins.names:
return None
plugin = plugins[name]
return plugin.load()
def load_all(group: str) -> Any:
"""Loads all plugins using entry point specification.
Args:
group: Name of plugin group.
Returns:
Classes from specified group.
"""
plugins = entry_points(group=group)
return [plugin.load() for plugin in plugins]