optional
_optional ¶
ImportErrorHandle ¶
Bases: Enum
List of values defining how to handle import errors.
import_optional_dependencies ¶
import_optional_dependencies(
dependency_group: str,
modules: list[str],
error: ImportErrorHandle = ImportErrorHandle.RAISE,
) -> None
Import list of optional dependencies.
PARAMETER | DESCRIPTION |
---|---|
dependency_group
|
Name of optional group that contains dependencies.
TYPE:
|
modules
|
List of module names that are expected to be imported.
TYPE:
|
error
|
Information what to do when any of the modules hasn't been found. Defaults to ErrorHandle.RAISE.
TYPE:
|
Source code in srai/_optional.py
import_optional_dependency ¶
import_optional_dependency(
dependency_group: str,
module: str,
name: Optional[str] = None,
error: ImportErrorHandle = ImportErrorHandle.RAISE,
) -> Optional[ModuleType]
Import a module or a element from the module.
PARAMETER | DESCRIPTION |
---|---|
dependency_group
|
Name of dependency group where dependency is defined. Helps communicate a proper error message to the end user.
TYPE:
|
module
|
Name of a module.
TYPE:
|
name
|
Name of element from the module. If none, returns whole module. Otherwise returns a submodule found using a given name. Defaults to None.
TYPE:
|
error
|
Information what to do when module hasn't
been found. Can
TYPE:
|
RAISES | DESCRIPTION |
---|---|
ImportError
|
When required dependency is not installed. |
RETURNS | DESCRIPTION |
---|---|
Optional[ModuleType]
|
Optional[ModuleType]: Module or submodule imported using a name. None if not found. |