Added manager and register. /JL

This commit is contained in:
2024-07-17 18:50:47 +02:00
parent 59fc0ef000
commit e74b780017
4 changed files with 22 additions and 1 deletions

View File

@@ -1,2 +1,4 @@
from . import pluginlib_init
from . import pluginlib_manager
from . import pluginlib_register
from . import pluginlib_relay

View File

@@ -1,3 +1,3 @@
[pluginlib]
build = 5
build = 6

View File

View File

@@ -0,0 +1,19 @@
import importlib.metadata as importlib_metadata
def register_plugin(name, namespace, entry_point) -> None:
"""Registers a plugin dynamically without needing to install as a package.
Args:
name (str): Name of plugin to be referenced.
namespace (str): Name of plugin namespace.
entry_point (str): Entry point in the form: some.module:some.attr
"""
ep = importlib_metadata.EntryPoint(name, entry_point, namespace)
e = ExtensionManager(namespace)
if namespace in e.ENTRY_POINT_CACHE:
entry_points = e.ENTRY_POINT_CACHE.get(namespace)
if name not in [entry_point.name for entry_point in entry_points]:
entry_points.append(ep)
e.ENTRY_POINT_CACHE[namespace] = entry_points
else:
e.ENTRY_POINT_CACHE[namespace] = [ep]
ep.load()