requires
requires
⚓︎
requires
~ dependency utils
Classes⚓︎
requires.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)
dataclass
⚓︎
Functions⚓︎
requires.Requirement.import_requirement() -> Any
⚓︎
Import and return the requirement
Source code in libs/requires/requires/core.py
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 |
|
requires.RequirementAttributeError
⚓︎
Bases: AttributeError
Requirement attribute error
requires.RequirementError
⚓︎
Bases: ModuleNotFoundError
Exception for requires
Functions⚓︎
requires.requires(*requirements: Union[str, Dict[str, str], 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) -> Callable[[Callable[..., T]], Callable[..., T]]
⚓︎
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:
Name | Type | Description | Default |
---|---|---|---|
*requirements
|
Union[str, Dict[str, str], Requirement]
|
Any number of required package names as strings |
()
|
_import
|
'str'
|
|
None
|
_as
|
'str'
|
|
None
|
_from
|
'str'
|
|
None
|
pip
|
Optional[Union[str, bool]]
|
pip install name |
None
|
conda
|
Optional[Union[str, bool]]
|
conda install name |
None
|
conda_forge
|
Optional[Union[str, bool]]
|
conda-forge install name |
None
|
details
|
str
|
details to be displayed in the error message |
None
|
Returns:
Type | Description |
---|---|
Callable[[Callable[..., T]], Callable[..., T]]
|
Function wrapped such that in the event of a |
Callable[[Callable[..., T]], Callable[..., T]]
|
error is raised. |
Raises:
Type | Description |
---|---|
ValueError
|
If requirements or kwargs are given |
Source code in libs/requires/requires/core.py
340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 |
|
Modules⚓︎
requires.__about__
⚓︎
Package metadata/info
requires.__main__
⚓︎
pkg entry ~ python -m requires
Functions⚓︎
requires.__main__.main() -> None
⚓︎
Print package metadata
Source code in libs/requires/requires/__main__.py
11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
|
requires.core
⚓︎
Core for requires
Classes⚓︎
requires.core.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)
dataclass
⚓︎
requires.core.Requirement.import_requirement() -> Any
⚓︎Import and return the requirement
Source code in libs/requires/requires/core.py
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 |
|
requires.core.RequirementAttributeError
⚓︎
Bases: AttributeError
Requirement attribute error
requires.core.RequirementDict
⚓︎
Bases: TypedDict
Requirement dict
requires.core.RequirementError
⚓︎
Bases: ModuleNotFoundError
Exception for requires
Functions⚓︎
requires.core.parse_name_error(ne: NameError) -> List[str]
⚓︎
Return a list of the missing items specified in a NameError
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ne
|
NameError
|
NameError object |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
List[str]
|
name of the missing thing/pkg/module/function |
Examples:
>>> args = ("name 'path' is not defined",)
>>> ne = NameError(*args)
>>> parse_name_error(ne)
['path']
Source code in libs/requires/requires/core.py
257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 |
|
requires.core.requires(*requirements: Union[str, Dict[str, str], 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) -> Callable[[Callable[..., T]], Callable[..., T]]
⚓︎
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:
Name | Type | Description | Default |
---|---|---|---|
*requirements
|
Union[str, Dict[str, str], Requirement]
|
Any number of required package names as strings |
()
|
_import
|
'str'
|
|
None
|
_as
|
'str'
|
|
None
|
_from
|
'str'
|
|
None
|
pip
|
Optional[Union[str, bool]]
|
pip install name |
None
|
conda
|
Optional[Union[str, bool]]
|
conda install name |
None
|
conda_forge
|
Optional[Union[str, bool]]
|
conda-forge install name |
None
|
details
|
str
|
details to be displayed in the error message |
None
|
Returns:
Type | Description |
---|---|
Callable[[Callable[..., T]], Callable[..., T]]
|
Function wrapped such that in the event of a |
Callable[[Callable[..., T]], Callable[..., T]]
|
error is raised. |
Raises:
Type | Description |
---|---|
ValueError
|
If requirements or kwargs are given |
Source code in libs/requires/requires/core.py
340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 |
|
requires.core.requires_python(version: str) -> None
⚓︎
Decorator to specify the python version a function or class requires
Source code in libs/requires/requires/core.py
404 405 406 |
|