In [1]: %time import kikuchipy as kp
CPU times: user 7.65 s, sys: 556 ms, total: 8.21 s
Wall time: 7.54 s
After this PR:
In [1]: %time import kikuchipy as kp
CPU times: user 431 ms, sys: 164 ms, total: 596 ms
Wall time: 340 ms
Note that the import time of from kikuchipy.signals import EBSD does not change, as that import triggers all the imports in kikuchipy/signals/ebsd.py both before and after this PR.
For reviewers
[ ] The PR title is short, concise, and will make sense 1 year later.
[ ] New functions are imported in corresponding __init__.py.
[ ] New features, API changes, and deprecations are mentioned in the unreleased
section in CHANGELOG.rst.
[ ] New contributors are added to release.py and .all-contributorsrc and the table
is regenerated.
Description of the change
This PR introduces lazy imports of modules, following the specification in PEP 562.
The implementation in https://github.com/hyperspy/hyperspy/pull/2850 helped a lot when figuring out a nice way to test lazy importing, thanks @ericpre!
Progress of the PR
Minimal example of the bug fix or new feature
Before this PR:
After this PR:
Note that the import time of
from kikuchipy.signals import EBSD
does not change, as that import triggers all the imports inkikuchipy/signals/ebsd.py
both before and after this PR.For reviewers
__init__.py
.CHANGELOG.rst
.release.py
and.all-contributorsrc
and the table is regenerated.