ImagingDataCommons / highdicom

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

compatibility with `coverage`? #188

Closed wyli closed 2 years ago

wyli commented 2 years ago

I came across this issue when importing highdicom with coverage:

pip install highdicom
echo "import highdicom" > my_test.py
coverage run my_test.py

it seems the import always takes a long time, compared with other python packages such as numpy.

here is a minimal example in colab: https://colab.research.google.com/drive/18qCwaHr3CWhvTmdY8dZKA2Pn0dDzlmvR Screenshot 2022-07-19 at 14 06 27

CPBridge commented 2 years ago

This is speculation but I imagine that this is probably due to just a couple of files within highdicom. The package contains a large part of the DICOM standard specification scraped from the standard itself and placed into nested Python list/dictionary structures within the modules highdicom._modules and (to a lesser extent) highdicom._iods. These files are therefore very large and can cause coverage tools to work very slowly (especially the first time, when many build a cache that will speed up subsequent runs).

I'm not an expert on coverage, but is there some way to manually exclude those files?

wyli commented 2 years ago

Thanks, that's probably the issue. I couldn't find a way to exclude the files. on the other hand, I think it might be useful for highdicom to consider other possibilities of packaging that static standard specification? and perhaps improve the import by loading the module attributes lazily only when the users request them?

CPBridge commented 2 years ago

@wyli see #196 for a solution to your issue

wyli commented 2 years ago

@wyli see #196 for a solution to your issue

thanks!

CPBridge commented 2 years ago

There is still room for improvement here, but marking this immediate issue as resolved

wyli commented 2 years ago

thank you, in the colab notebook now it works fine!

!pip install coverage
!pip install git+https://github.com/herrmannlab/highdicom.git
!echo "import highdicom" > my_test.py
!coverage run my_test.py