Skip to content

Commit 98b2504

Browse files
committed
make obstore an optional dependency with runtime import check
1 parent e836360 commit 98b2504

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

src/mdio/api/io.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
from typing import Literal
77

88
import zarr
9-
from obstore.store import from_url as obstore_from_url
109
from upath import UPath
1110
from xarray import Dataset as xr_Dataset
1211
from xarray import open_zarr as xr_open_zarr
@@ -17,6 +16,12 @@
1716
from mdio.constants import ZarrFormat
1817
from mdio.core.zarr_io import zarr_warnings_suppress_unstable_structs_v3
1918

19+
# optional runtime import
20+
try:
21+
from obstore.store import from_url as obstore_from_url
22+
except ImportError:
23+
obstore_from_url = None
24+
2025
if TYPE_CHECKING:
2126
from collections.abc import Mapping
2227
from pathlib import Path
@@ -37,6 +42,10 @@ def _normalize_path(path: UPath | Path | str) -> UPath:
3742

3843
def _get_store(upath: UPath, storage_backend: StorageBackendT) -> Store:
3944
if storage_backend == "obstore":
45+
if obstore_from_url is None:
46+
msg = "Optional dependency 'obstore' is not installed. Install it with `pip install multidimio[cloud]`."
47+
raise RuntimeError(msg)
48+
4049
uri = upath.as_posix()
4150
storage_options: Mapping[str, Any] = getattr(upath, "storage_options", {})
4251
return ObjectStore(obstore_from_url(uri, **storage_options))

0 commit comments

Comments
 (0)