scine_puffin.utilities.imports¶
Functions
|
Automatically loads the calculators if they are in the dependency list. |
|
A utility function that adds the "scine" prefix to specific Scine dependencies and adds additional dependencies based on the given dependencies, such as the utilities package or the Sparrow calculator to the ReaDuct dependency. |
|
Allows checking if a Python module is installed with the Python module given as a string. |
|
This function is meant to be used as a decorator for functions that require specific dependencies to be installed. |
Classes
|
This class is meant to be used as a placeholder for missing dependencies. |
Exceptions
- class scine_puffin.utilities.imports.MissingDependency(name, doc=None)[source]¶
This class is meant to be used as a placeholder for missing dependencies. It allows access to arbitrarily named attributes and methods, but raises a MissingDependencyError when accessed or called.
- exception scine_puffin.utilities.imports.MissingDependencyError[source]¶
- args¶
- with_traceback()¶
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- scine_puffin.utilities.imports.calculator_import_resolve(dependency_list: List[str]) None [source]¶
Automatically loads the calculators if they are in the dependency list.
- Parameters:
- dependency_listList[str]
The list of dependencies.
- scine_puffin.utilities.imports.dependency_addition(dependencies: List[str]) List[str] [source]¶
A utility function that adds the “scine” prefix to specific Scine dependencies and adds additional dependencies based on the given dependencies, such as the utilities package or the Sparrow calculator to the ReaDuct dependency.
- Parameters:
- dependenciesList[str]
The list of dependencies.
- Returns:
- List[str]
The updated list of dependencies with proper “scine” prefixes and additional dependencies.
- scine_puffin.utilities.imports.module_exists(module_name: str) bool [source]¶
Allows checking if a Python module is installed with the Python module given as a string. Additionally, also checks for environment variables for specific programs that can be available to the Puffin such as different quantum chemistry programs.
- Parameters:
- module_namestr
The name of the module to check for.
- Returns:
- bool
True if the module is installed, False otherwise.
Examples
This function alleviates the challenge that no Scine module is a hard dependency for Puffin in order to allow the Puffin to bootstrap itself by building the Scine modules, but also relies on the Scine modules in almost all jobs. The usage should be to add >>> from __future__ import annotations >>> from typing import TYPE_CHECKING
to the top of the file and then use the function straight after the imports as follows: >>> if module_exists(“scine_database”) or TYPE_CHECKING: >>> import scine_database as db
this allows typehinting all functions with database objects and still makes the file importable without the database module.
- scine_puffin.utilities.imports.requires(*dependencies) Callable [source]¶
This function is meant to be used as a decorator for functions that require specific dependencies to be installed. It checks if the given dependencies are installed and raises an ImportError if not. Then it automatically loads the calculators if they are in the dependency list.
- Returns:
- Callable
The wrapped function.
- Raises:
- MissingDependencyError
If the given dependencies are not installed, but the function is called.
Examples
Add this function as a decorator with the required modules as arguments
>>> @requires("readuct", "database") >>> def function(): >>> ...