Plugin Loader utility
pydantic_modelable.loader.PluginLoader
Bases: Generic[LoadedEntry]
A Python package dynamic loader utility, tracking what modules where loaded.
The PluginLoader class is generic to allow enforcing type-hints over the loaded modules or attributes. It keeps a dict of the loaded modules, to facilitate various uses: - generic usage of the loaded modules/module-attributes - debugging purposes
The provided type should ideally be a typing.Protocol based type, ensuring the loaded modules and/or attributes are loosely tied to the type-hint.
To use it, one should preferably specify the LoadedEntry type explicitly:
from typing import Any
from pydantic_modelable import PluginLoader
# Here we load whole modules, so `Any` is our best fit :(
loader = PluginLoader[Any]('my-module')
loaded
property
Return a shallow copy of the loaded modules dict.
The shallow copy aims to reduce risk of the calling code altering the object's internal state.
__init__(root_module_name='pydantic-modelable', load_attribute=None)
Instanciate and Configure a PluginLoader object.
The object's initialization parameters allow defining how the plugin modules will be loaded:
root_module_name: Optional name of the python module to load dependants for. Defaults to pydantic_modelable.load_attribute: Optional attribute name, for situations where the wanted item is an attribute of the module, and not the whole module.depend_on: Name of the module for which we want to load the "extensions" (module depending on it).
load()
Load all the modules depending (directly or indirectly) on depend_on.
The modules are loaded based on the initialization parameter of the loader object (module name, specific attribute or not, etc).