requires
⚓︎
requires
~ dependency utils
Modules:
-
core
–Core for requires
-
shed
–Pre-fab requirements
Classes:
-
Requirement
– -
RequirementAttributeError
–Requirement attribute error
-
RequirementDict
–Requirement dict
-
RequirementError
–Exception for requires
-
RequirementProxy
– -
RequirementWarning
–Warning for requires
-
RequirementsMeta
–
Functions:
-
preflight_check
–Scan and check calling module scope for objs/fns wrapped with requirements.
-
requires
–Decorator to specify the packages a function or class requires
-
requires_python
–Decorator to specify the python version a function or class requires
-
scope_requirements
–Scan and check calling module scope for objs/fns wrapped with requirements.
Requirement
dataclass
⚓︎
Requirement(
_import: str,
_from: Optional[str] = None,
_as: Optional[str] = None,
pip: Optional[Union[str, bool]] = None,
conda: Optional[Union[str, bool]] = None,
conda_forge: Optional[Union[str, bool]] = None,
details: Optional[Union[str, List[str]]] = None,
lazy: bool = True,
)
Methods:
-
import_requirement
–Import and return the requirement
RequirementAttributeError
⚓︎
Bases: AttributeError
Requirement attribute error
RequirementError
⚓︎
Bases: ModuleNotFoundError
Exception for requires
RequirementWarning
⚓︎
Bases: UserWarning
Warning for requires
RequirementsMeta
dataclass
⚓︎
RequirementsMeta(requirements: Set[Requirement] = set())
Methods:
-
preflight_check
–Check if requirements are met
preflight_check
⚓︎
preflight_check(
*,
warn: bool = False,
on_missing: Optional[
Callable[[Set[Requirement]], None]
],
) -> Set[Requirement]
Check if requirements are met
Parameters:
-
warn
⚓︎bool
, default:False
) –If True, issues warnings for missing requirements.
-
on_missing
⚓︎Optional[Callable[[Set[Requirement]], None]]
) –Callback to do something on missing requirements.
Returns:
-
Set[Requirement]
–Set[Requirement]: A set of missing requirements
preflight_check
⚓︎
preflight_check(
*,
warn: bool = False,
on_missing: Optional[
Callable[[Set[Requirement]], None]
] = None,
) -> RequirementsMeta
Scan and check calling module scope for objs/fns wrapped with requirements.
Parameters:
-
warn
⚓︎bool
, default:False
) –If True, issues warnings for missing requirements.
-
on_missing
⚓︎Optional[Callable[[Set[Requirement]], None]]
, default:None
) –Callback to do something on missing requirements.
Returns:
-
RequirementsMeta
(RequirementsMeta
) –A RequirementsMeta instance with the requirements found during the check.
requires
⚓︎
requires(
*requirements: Union[
str, TRequirementDict, Requirement
],
_import: Optional[str] = None,
_as: Optional[str] = None,
_from: Optional[str] = None,
pip: Optional[Union[str, bool]] = None,
conda: Optional[Union[str, bool]] = None,
conda_forge: Optional[Union[str, bool]] = None,
details: Optional[str] = None,
lazy: Optional[bool] = None,
) -> Callable[[Callable[P, R]], Callable[P, R]]
Decorator to specify the packages a function or class requires
The decorator will not do anything unless a NameError is thrown. If a
NameError is thrown then the required package is likely not installed and
a RequirementError
will be thrown with instructions on how to install
the required packages.
Parameters:
-
*requirements
⚓︎Union[str, TRequirementDict, Requirement]
, default:()
) –Any number of required package names as strings
-
_import
⚓︎'str'
, default:None
) –IMPORT
part offrom {FROM} import {IMPORT} as {AS}
-
_as
⚓︎'str'
, default:None
) –AS
part offrom {FROM} import {IMPORT} as {AS}
-
_from
⚓︎'str'
, default:None
) –FROM
part offrom {FROM} import {IMPORT} as {AS}
-
pip
⚓︎Optional[Union[str, bool]]
, default:None
) –pip install name
-
conda
⚓︎Optional[Union[str, bool]]
, default:None
) –conda install name
-
conda_forge
⚓︎Optional[Union[str, bool]]
, default:None
) –conda-forge install name
-
details
⚓︎str
, default:None
) –details to be displayed in the error message
-
lazy
⚓︎bool
, default:None
) –If True, the requirement is loaded lazily
Returns:
-
Callable[[Callable[P, R]], Callable[P, R]]
–Function wrapped such that in the event of a
NameError
a helpful -
Callable[[Callable[P, R]], Callable[P, R]]
–error is raised.
Raises:
-
ValueError
–If requirements or kwargs are given
requires_python
⚓︎
requires_python(version: str) -> None
Decorator to specify the python version a function or class requires
scope_requirements
⚓︎
scope_requirements(debug: bool = False) -> RequirementsMeta
Scan and check calling module scope for objs/fns wrapped with requirements.
Parameters:
Returns:
-
RequirementsMeta
(RequirementsMeta
) –A RequirementsMeta instance with the requirements found during the check.