Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions docs/release.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ Fixes

Improvements
~~~~~~~~~~~~
* If an import error is raised when trying to define a codec that is *not*
an optional dependency, it is no longer silently caught. Instead it will
be propagated to the user, as this indicates an issue with the installed
package.

Import errors caused by optional dependencies (ZFPY, MsgPack, CRC32C, and PCodec)
are still silently caught.
By :user:`David Stansby <dstansby>`, :issue:`550`.


0.14.1
Expand Down
89 changes: 43 additions & 46 deletions numcodecs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,41 +36,32 @@

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

with suppress(ImportError):
from numcodecs.zfpy import ZFPY

register_codec(ZFPY)
register_codec(LZ4)

from numcodecs.astype import AsType

Expand Down Expand Up @@ -112,38 +103,44 @@

register_codec(BitRound)

with suppress(ImportError):
from numcodecs.msgpacks import MsgPack

register_codec(MsgPack)

from numcodecs.checksum32 import CRC32, Adler32, JenkinsLookup3

register_codec(CRC32)
register_codec(Adler32)
register_codec(JenkinsLookup3)

with suppress(ImportError):
from numcodecs.checksum32 import CRC32C

register_codec(CRC32C)

from numcodecs.json import JSON

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 VLenArray, VLenBytes, VLenUTF8

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
# Optional depenedencies
with suppress(ImportError):
from numcodecs.zfpy import ZFPY

register_codec(ZFPY)

Check warning on line 131 in numcodecs/__init__.py

View check run for this annotation

Codecov / codecov/patch

numcodecs/__init__.py#L131

Added line #L131 was not covered by tests

with suppress(ImportError):
from numcodecs.msgpacks import MsgPack

register_codec(MsgPack)

with suppress(ImportError):
from numcodecs.checksum32 import CRC32C

register_codec(CRC32C)

with suppress(ImportError):
from numcodecs.pcodec import PCodec

register_codec(PCodec)
register_codec(PCodec)
Loading