zokyo.decorators module

Since we don’t force some packages to be build-time requirements, these functions are used to decorate methods that require said packages. Internally, it checks on the availability of the package before calling the function. All library imports should take place inside the method body.

zokyo.decorators.depends_on(*packages)[source]

A class or function decorator for callables that depend on packages

Either a number of package names or mappings from package import names to package install names:

>>> @depends_on('scipy', {'sklearn': 'scikit-learn'}, 'a_fake_pkg')
... class SomeClass:
...     pass
>>> SomeClass()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: SomeClass requires a_fake_pkg

>>> @depends_on('scipy', 'numpy')
... def do_something_cool():
...     print('ayyy')
>>> do_something_cool()
ayyy
zokyo.decorators.deprecated(use_instead_msg)[source]
zokyo.decorators.timer(func)[source]

Print the runtime of the decorated function