generated from Lerking/python-module-repo-template
Added manager and register. /JL
This commit is contained in:
@@ -1,2 +1,4 @@
|
||||
from . import pluginlib_init
|
||||
from . import pluginlib_manager
|
||||
from . import pluginlib_register
|
||||
from . import pluginlib_relay
|
@@ -1,3 +1,3 @@
|
||||
[pluginlib]
|
||||
build = 5
|
||||
build = 6
|
||||
|
||||
|
0
src/pluginlib/pluginlib_manager.py
Normal file
0
src/pluginlib/pluginlib_manager.py
Normal file
19
src/pluginlib/pluginlib_register.py
Normal file
19
src/pluginlib/pluginlib_register.py
Normal 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()
|
Reference in New Issue
Block a user