hyrax.plugin_utils

Attributes

logger

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.

save_to_tensor(to_tensor_fn, save_path)

Save a to_tensor function to a specified path.

load_to_tensor(load_path)

Load a to_tensor function from a specified path.

Module Contents

logger[source]
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.

save_to_tensor(to_tensor_fn, save_path: pathlib.Path)[source]

Save a to_tensor function to a specified path.

Parameters:
  • to_tensor_fn (function) – The to_tensor function to save.

  • save_path (str) – The path to save the to_tensor function to.

load_to_tensor(load_path: pathlib.Path)[source]

Load a to_tensor function from a specified path.

Parameters:

load_path (str) – The directory containing the to_tensor.py module to load.

Returns:

The loaded to_tensor function.

Return type:

function