diff --git a/pyproject.toml b/pyproject.toml index 2b41dd03..77998076 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -32,18 +32,17 @@ dependencies = [ [project.optional-dependencies] hdf_reader = [ "fsspec", + "h5py", "hdf5plugin", "imagecodecs", "imagecodecs-numcodecs==2024.6.1", + "numcodecs" ] test = [ "codecov", "fastparquet", "fsspec", "h5py", - "hdf5plugin", - "imagecodecs", - "imagecodecs-numcodecs==2024.6.1", "kerchunk>=0.2.5", "mypy", "netcdf4", @@ -57,6 +56,7 @@ test = [ "ruff", "s3fs", "scipy", + "virtualizarr[hdf_reader]" ] diff --git a/virtualizarr/readers/hdf/hdf.py b/virtualizarr/readers/hdf/hdf.py index 6f01c1eb..a942268c 100644 --- a/virtualizarr/readers/hdf/hdf.py +++ b/virtualizarr/readers/hdf/hdf.py @@ -1,4 +1,5 @@ import math +from dataclasses import dataclass from typing import TYPE_CHECKING, Dict, Iterable, List, Mapping, Optional, Union import numpy as np @@ -21,6 +22,15 @@ h5py = soft_import("h5py", "For reading hdf files", strict=False) +if not h5py: + + @dataclass + class h5py_stub: + Group: str + Dataset: str + + h5py = h5py_stub(Group="", Dataset="") + class HDFVirtualBackend(VirtualBackend): @staticmethod