Skip to content

Commit 6967461

Browse files
yarikopticeffigies
authored andcommitted
RF: minc - delay import of h5py until needed.
On Debian systems h5py comes with MPI enabled build. I guess on some misconfigured systems, like my laptop, it might take awhile to import. And since h5py here is imported upon import of `nibabel`, it makes it long(er) to import it. Here is timing on my laptop before the change: $> time python -c 'import nibabel' python -c 'import nibabel' 0.20s user 0.08s system 5% cpu 5.356 total and here is after the change: $> time python -c 'import nibabel' python -c 'import nibabel' 0.13s user 0.02s system 100% cpu 0.150 total
1 parent 50265dc commit 6967461

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

nibabel/minc2.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import numpy as np
2929

3030
from .keywordonly import kw_only_meth
31-
from ._h5py_compat import h5py
3231

3332
from .minc1 import Minc1File, MincHeader, Minc1Image, MincError
3433

@@ -160,6 +159,9 @@ class Minc2Image(Minc1Image):
160159
@classmethod
161160
@kw_only_meth(1)
162161
def from_file_map(klass, file_map, mmap=True, keep_file_open=None):
162+
# Import of h5py might take awhile for MPI-enabled builds
163+
# So we are importing it here "on demand"
164+
from ._h5py_compat import h5py
163165
holder = file_map['image']
164166
if holder.filename is None:
165167
raise MincError('MINC2 needs filename for load')

0 commit comments

Comments
 (0)