Skip to content

Commit

Permalink
Disable PCodec if dependencies are unavailable
Browse files Browse the repository at this point in the history
  • Loading branch information
jakirkham committed Nov 18, 2024
1 parent 145f57c commit d1f76fc
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 13 deletions.
5 changes: 3 additions & 2 deletions numcodecs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@

register_codec(Fletcher32)

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

register_codec(PCodec)
register_codec(PCodec)
8 changes: 1 addition & 7 deletions numcodecs/pcodec.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
from numcodecs.abc import Codec
from numcodecs.compat import ensure_contiguous_ndarray

try:
from pcodec import ChunkConfig, ModeSpec, PagingSpec, standalone
except ImportError: # pragma: no cover
standalone = None
from pcodec import ChunkConfig, ModeSpec, PagingSpec, standalone


DEFAULT_MAX_PAGE_N = 262144
Expand Down Expand Up @@ -49,9 +46,6 @@ def __init__(
# TODO one day, add support for the Try* mode specs
mode_spec: Literal['auto', 'classic'] = 'auto',
):
if standalone is None: # pragma: no cover
raise ImportError("pcodec must be installed to use the PCodec codec.")

# note that we use `level` instead of `compression_level` to
# match other codecs
self.level = level
Expand Down
5 changes: 1 addition & 4 deletions numcodecs/tests/test_pcodec.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import numpy as np
import pytest

from numcodecs.pcodec import PCodec

try:
# initializing codec triggers ImportError
PCodec()
from numcodecs.pcodec import PCodec
except ImportError: # pragma: no cover
pytest.skip("pcodec not available", allow_module_level=True)

Expand Down

0 comments on commit d1f76fc

Please sign in to comment.