Towards less eager imports
Defer imports in gpaw/__init__.py
.
It's tricky to intercept the imports through the CLI back-and-forth, and that shows. We could consider switching to click
.
Anway: In current master, importing GPAW increases the number of loaded modules like this:
askhl@alberich:~$ python3 count_imports.py
Imports from gpaw module 55 -> 877
With this branch, the number is:
askhl@alberich:~$ python3 count_imports.py
Imports from gpaw module 55 -> 74
The script for counting the imports is:
import sys
mods = set(sys.modules)
import gpaw
mods2 = set(sys.modules)
print('Imports from gpaw module', f'{len(mods)} -> {len(mods2)}')
# print(' '.join(sorted(mods2 - mods)))
Edited by Ask Hjorth Larsen