ImagingDataCommons / highdicom

High-level DICOM abstractions for the Python programming language
https://highdicom.readthedocs.io
MIT License
168 stars 35 forks source link

Remove module level imports of module data to speed up module import #196

Closed CPBridge closed 2 years ago

CPBridge commented 2 years ago

As noted in #188, importing highdicom requires importing the very large data structures in highdicom._iods and highdicom._modules. This slows down imports somewhat, but more importantly slows down coverage based tests like coverage run very considerably when often this is unnecessary because the data will not actually be used.

This PR swaps all imports from these modules to be lazily evaluated. With this change, the test that @wyli reported took an very long time now completes almost instantaneously. Of course coverage tests that run on functions that make use of the data in these modules will still be slow, but at least now simple tests will run faster.

As far as I'm aware, there are no significant downsides to this.

CPBridge commented 2 years ago

@hackermd should we consider moving this data to a JSON file (or similar) so that no coverage tool will try to assess coverage of these files?