pyxem / kikuchipy

Toolbox for analysis of electron backscatter diffraction (EBSD) patterns
https://kikuchipy.org
GNU General Public License v3.0
81 stars 30 forks source link

Load imports lazily #551

Closed hakonanes closed 2 years ago

hakonanes commented 2 years ago

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:

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