From a8cc82f9508fa724c73eeb8f47162d73c3c944ca Mon Sep 17 00:00:00 2001 From: sharkinsspatial Date: Mon, 18 Nov 2024 14:21:55 -0500 Subject: [PATCH] Attempt at nested optional depedency usage. --- pyproject.toml | 6 +++--- virtualizarr/readers/hdf/hdf.py | 10 ++++++++++ 2 files changed, 13 insertions(+), 3 deletions(-) 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