polymerist.genutils.importutils.dependencies
Utilities for checking and enforcing module dependencies within code
Attributes
Exceptions
Raised when a package dependency cannot be found and the user should be alerted with install instructions |
Functions
|
Check whether a module of the given name is present on the system |
|
Check whether one or more modules are all present |
|
Decorator which enforces optional module dependencies prior to function execution |
Module Contents
- polymerist.genutils.importutils.dependencies.Params
- polymerist.genutils.importutils.dependencies.ReturnType
- polymerist.genutils.importutils.dependencies.TCall
- exception polymerist.genutils.importutils.dependencies.MissingPrerequisitePackage(importing_package_name: str, use_case: str, install_link: str, dependency_name: str, dependency_name_formal: str | None = None)[source]
Bases:
ExceptionRaised when a package dependency cannot be found and the user should be alerted with install instructions
- polymerist.genutils.importutils.dependencies.module_installed(module_name: str) bool[source]
Check whether a module of the given name is present on the system
- Parameters:
module_name (str) – The name of the module, as it would occur in an import statement Do not support direct passing of module objects to avoid circularity (i.e. no reason to check if a module is present if one has already imported it elsewhere)
- Returns:
module_found – Whether or not the module was found to be installed in the current working environment
- Return type:
bool
- polymerist.genutils.importutils.dependencies.modules_installed(*module_names: list[str]) bool[source]
Check whether one or more modules are all present Will only return true if ALL specified modules are found
- Parameters:
module_names (**str*) – Any number of module names, passed as a comma-separated sequence of strings
- Returns:
all_modules_found – Whether or not all modules were found to be installed in the current working environment
- Return type:
bool
- polymerist.genutils.importutils.dependencies.requires_modules(*required_module_names: list[str], missing_module_error: Exception | type[Exception] = ImportError) Callable[[TCall[Ellipsis, ReturnType]], TCall[Ellipsis, ReturnType]][source]
Decorator which enforces optional module dependencies prior to function execution
- Parameters:
module_names (**str*) – Any number of module names, passed as a comma-separated sequence of strings
missing_module_error (type[Exception], default ImportError) – The type of Exception to raise if a module is not found installed Defaults to ImportError
- :raises ImportErrorException: Raised if any of the specified packages is not found to be installed
Exception message will indicate the name of the specific package found missing