32 lines
838 B
Python
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]
|