pyufunc.requires#

pyufunc.requires(*args, **kwargs)#

Wrap a function with extra dependency checks.

If the dependencies are not available, the function will not run.

Parameters:
  • *args – Required dependency specifications. Each value can be a package name string, or a two-item tuple/list of (install_name, import_name) when the installation name differs from the import name.

  • **kwargs – Optional decorator settings. Supported keys are verbose for printing dependency messages and auto_install for explicitly installing missing packages. verbose defaults to True and auto_install defaults to False.

Notes

Missing dependencies are reported and the wrapped function is skipped. Dependencies are installed only when auto_install=True is passed explicitly.

Examples

>>> @requires("numpy", "pandas", verbose=False)
... def my_function():
...     return "I'm running!"
>>> my_function()
"I'm running!"
Returns:

The decorated function wrapper.