Skip to content

Commit cb1f090

Browse files
committed
Only suppress imports of optional external dependencies
1 parent a7b8909 commit cb1f090

File tree

1 file changed

+31
-32
lines changed

1 file changed

+31
-32
lines changed

numcodecs/__init__.py

Lines changed: 31 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -37,37 +37,34 @@
3737

3838
register_codec(BZ2)
3939

40-
with suppress(ImportError):
41-
from numcodecs.lzma import LZMA
40+
from numcodecs.lzma import LZMA
4241

43-
register_codec(LZMA)
42+
register_codec(LZMA)
4443

45-
with suppress(ImportError):
46-
from numcodecs import blosc
47-
from numcodecs.blosc import Blosc
48-
49-
register_codec(Blosc)
50-
# initialize blosc
51-
try:
52-
ncores = multiprocessing.cpu_count()
53-
except OSError: # pragma: no cover
54-
ncores = 1
55-
blosc.init()
56-
blosc.set_nthreads(min(8, ncores))
57-
atexit.register(blosc.destroy)
44+
from numcodecs import blosc
45+
from numcodecs.blosc import Blosc
5846

59-
with suppress(ImportError):
60-
from numcodecs import zstd
61-
from numcodecs.zstd import Zstd
47+
register_codec(Blosc)
48+
# initialize blosc
49+
try:
50+
ncores = multiprocessing.cpu_count()
51+
except OSError: # pragma: no cover
52+
ncores = 1
53+
blosc.init()
54+
blosc.set_nthreads(min(8, ncores))
55+
atexit.register(blosc.destroy)
6256

63-
register_codec(Zstd)
57+
from numcodecs import zstd
58+
from numcodecs.zstd import Zstd
6459

65-
with suppress(ImportError):
66-
from numcodecs import lz4
67-
from numcodecs.lz4 import LZ4
60+
register_codec(Zstd)
6861

69-
register_codec(LZ4)
62+
from numcodecs import lz4
63+
from numcodecs.lz4 import LZ4
7064

65+
register_codec(LZ4)
66+
67+
# zfpy is an optional external dependency
7168
with suppress(ImportError):
7269
from numcodecs.zfpy import ZFPY
7370

@@ -113,6 +110,7 @@
113110

114111
register_codec(BitRound)
115112

113+
# msgpack is an optional external dependency
116114
with suppress(ImportError):
117115
from numcodecs.msgpacks import MsgPack
118116

@@ -128,18 +126,19 @@
128126

129127
register_codec(JSON)
130128

131-
with suppress(ImportError):
132-
from numcodecs import vlen
133-
from numcodecs.vlen import VLenUTF8, VLenBytes, VLenArray
129+
from numcodecs import vlen
130+
from numcodecs.vlen import VLenUTF8, VLenBytes, VLenArray
134131

135-
register_codec(VLenUTF8)
136-
register_codec(VLenBytes)
137-
register_codec(VLenArray)
132+
register_codec(VLenUTF8)
133+
register_codec(VLenBytes)
134+
register_codec(VLenArray)
138135

139136
from numcodecs.fletcher32 import Fletcher32
140137

141138
register_codec(Fletcher32)
142139

143-
from numcodecs.pcodec import PCodec
140+
# pcodec is an optional external dependency
141+
with suppress(ImportError):
142+
from numcodecs.pcodec import PCodec
144143

145-
register_codec(PCodec)
144+
register_codec(PCodec)

0 commit comments

Comments
 (0)