hyrax.plugin_utils
==================

.. py:module:: hyrax.plugin_utils


Attributes
----------

.. autoapisummary::

   hyrax.plugin_utils.logger
   hyrax.plugin_utils.T


Functions
---------

.. autoapisummary::

   hyrax.plugin_utils.get_or_load_class
   hyrax.plugin_utils.import_module_from_string
   hyrax.plugin_utils.update_registry
   hyrax.plugin_utils.save_prepare_inputs
   hyrax.plugin_utils.load_prepare_inputs
   hyrax.plugin_utils.save_to_tensor
   hyrax.plugin_utils.load_to_tensor


Module Contents
---------------

.. py:data:: logger

.. py:data:: T

.. py:function:: get_or_load_class(class_name: str, registry: dict[str, T] | None = None) -> Union[T, Any]

   Given a configuration dictionary and a registry dictionary, attempt to return
   the requested class either from the registry or by dynamically importing it.

   :param class_name: The name of the class to load.
   :type class_name: str
   :param registry: The registry dictionary of <class name> : <class type> pairs.
   :type registry: dict

   :returns: The returned class to be instantiated
   :rtype: type


.. py:function:: import_module_from_string(module_path: str) -> Any

   Dynamically import a module from a string.

   :param module_path: The import spec for the requested class. Should be of the form:
                       "module.submodule.ClassName"
   :type module_path: str

   :returns: **returned_cls** -- The class type that was loaded.
   :rtype: type

   :raises AttributeError: If the class is not found in the module that is loaded.
   :raises ModuleNotFoundError: If the module is not found using the provided import spec.


.. py:function:: update_registry(registry: dict, name: str, class_type: type)

   Add a class to a given registry dictionary.

   :param registry: The registry to update.
   :type registry: dict
   :param name: The name of the class.
   :type name: str
   :param class_type: The class type to be instantiated.
   :type class_type: type


.. py:function:: save_prepare_inputs(prepare_inputs_fn, save_path: pathlib.Path)

   Save a prepare_inputs function to a specified path.

   :param prepare_inputs_fn: The prepare_inputs function to save.
   :type prepare_inputs_fn: collections.abc.Callable
   :param save_path: The path to save the prepare_inputs function to.
   :type save_path: pathlib.Path


.. py:function:: load_prepare_inputs(load_path: pathlib.Path)

   Load a prepare_inputs function from a specified path.

   :param load_path: The directory containing the `prepare_inputs.py` module to load.
   :type load_path: pathlib.Path

   :returns: The loaded prepare_inputs function.
   :rtype: collections.abc.Callable or None


.. py:function:: save_to_tensor(to_tensor_fn, save_path: pathlib.Path)

   Save a to_tensor function to a specified path.

   :param to_tensor_fn: The to_tensor function to save.
   :type to_tensor_fn: collections.abc.Callable
   :param save_path: The path to save the to_tensor function to.
   :type save_path: pathlib.Path


.. py:function:: load_to_tensor(load_path: pathlib.Path)

   Load a to_tensor function from a specified path.

   :param load_path: The directory containing the `to_tensor.py` module to load.
   :type load_path: pathlib.Path

   :returns: The loaded to_tensor function.
   :rtype: collections.abc.Callable or None


