hyrax.plugin_utils
Attributes
Functions
|
Given a configuration dictionary and a registry dictionary, attempt to return |
|
Dynamically import a module from a string. |
|
Add a class to a given registry dictionary. |
Module Contents
- get_or_load_class(config: dict, registry: dict[str, T] | None = None) T | Any[source]
Given a configuration dictionary and a registry dictionary, attempt to return the requested class either from the registry or by dynamically importing it.
- Parameters:
config (dict) – The configuration dictionary. Must contain the key, “name”.
registry (dict) – The registry dictionary of <class name> : <class type> pairs.
- Returns:
The returned class to be instantiated
- Return type:
type
- Raises:
ValueError – User failed to specify a class to load in the runtime configuration. No name key was found in the config.
- import_module_from_string(module_path: str) Any[source]
Dynamically import a module from a string.
- Parameters:
module_path (str) – The import spec for the model class. Should be of the form: “module.submodule.class_name”
- Returns:
model_cls – The model class.
- Return type:
type
- Raises:
AttributeError – If the model class is not found in the module that is loaded.
ModuleNotFoundError – If the module is not found using the provided import spec.