hyrax.plugin_utils

Attributes

T

Functions

get_or_load_class(→ Union[T, Any])

Given a configuration dictionary and a registry dictionary, attempt to return

import_module_from_string(→ Any)

Dynamically import a module from a string.

update_registry(registry, name, class_type)

Add a class to a given registry dictionary.

Module Contents

T[source]
get_or_load_class(class_name: str, 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:
  • class_name (str) – The name of the class to load.

  • registry (dict) – The registry dictionary of <class name> : <class type> pairs.

Returns:

The returned class to be instantiated

Return type:

type

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 requested class. Should be of the form: “module.submodule.ClassName”

Returns:

returned_cls – The class type that was loaded.

Return type:

type

Raises:
  • AttributeError – If the class is not found in the module that is loaded.

  • ModuleNotFoundError – If the module is not found using the provided import spec.

update_registry(registry: dict, name: str, class_type: type)[source]

Add a class to a given registry dictionary.

Parameters:
  • registry (dict) – The registry to update.

  • name (str) – The name of the class.

  • class_type (type) – The class type to be instantiated.