Skip to content

Commit

Permalink
Only suppress imports of optional external dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
dstansby committed Dec 3, 2024
1 parent d8a0a55 commit 7d0083d
Showing 1 changed file with 31 additions and 32 deletions.
63 changes: 31 additions & 32 deletions numcodecs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,37 +36,34 @@

register_codec(BZ2)

with suppress(ImportError):
from numcodecs.lzma import LZMA
from numcodecs.lzma import LZMA

register_codec(LZMA)
register_codec(LZMA)

with suppress(ImportError):
from numcodecs import blosc
from numcodecs.blosc import Blosc

register_codec(Blosc)
# initialize blosc
try:
ncores = multiprocessing.cpu_count()
except OSError: # pragma: no cover
ncores = 1
blosc.init()
blosc.set_nthreads(min(8, ncores))
atexit.register(blosc.destroy)
from numcodecs import blosc
from numcodecs.blosc import Blosc

with suppress(ImportError):
from numcodecs import zstd as zstd
from numcodecs.zstd import Zstd
register_codec(Blosc)
# initialize blosc
try:
ncores = multiprocessing.cpu_count()
except OSError: # pragma: no cover
ncores = 1
blosc.init()
blosc.set_nthreads(min(8, ncores))
atexit.register(blosc.destroy)

register_codec(Zstd)
from numcodecs import zstd as zstd
from numcodecs.zstd import Zstd

with suppress(ImportError):
from numcodecs import lz4 as lz4
from numcodecs.lz4 import LZ4
register_codec(Zstd)

register_codec(LZ4)
from numcodecs import lz4 as lz4
from numcodecs.lz4 import LZ4

register_codec(LZ4)

# zfpy is an optional external dependency
with suppress(ImportError):
from numcodecs.zfpy import ZFPY

Expand Down Expand Up @@ -112,6 +109,7 @@

register_codec(BitRound)

# msgpack is an optional external dependency
with suppress(ImportError):
from numcodecs.msgpacks import MsgPack

Expand All @@ -132,18 +130,19 @@

register_codec(JSON)

with suppress(ImportError):
from numcodecs import vlen as vlen
from numcodecs.vlen import VLenArray, VLenBytes, VLenUTF8
from numcodecs import vlen as vlen
from numcodecs.vlen import VLenUTF8, VLenBytes, VLenArray

register_codec(VLenUTF8)
register_codec(VLenBytes)
register_codec(VLenArray)
register_codec(VLenUTF8)
register_codec(VLenBytes)
register_codec(VLenArray)

from numcodecs.fletcher32 import Fletcher32

register_codec(Fletcher32)

from numcodecs.pcodec import PCodec
# pcodec is an optional external dependency
with suppress(ImportError):
from numcodecs.pcodec import PCodec

register_codec(PCodec)
register_codec(PCodec)

0 comments on commit 7d0083d

Please sign in to comment.