Skip to content

Commit

Permalink
Use guarded import of async fs wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
moradology committed Jan 13, 2025
1 parent c7e0f59 commit 4b8338f
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/zarr/storage/_fsspec.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import warnings
from typing import TYPE_CHECKING, Any

from fsspec.implementations.asyn_wrapper import AsyncFileSystemWrapper

from zarr.abc.store import ByteRangeRequest, Store
from zarr.storage._common import _dereference_path

Expand Down Expand Up @@ -169,7 +167,16 @@ def from_url(

fs, path = url_to_fs(url, **opts)
if not fs.async_impl:
fs = AsyncFileSystemWrapper(fs)
try:
from fsspec.implementations.asyn_wrapper import AsyncFileSystemWrapper

fs = AsyncFileSystemWrapper(fs)
except ImportError as e:
raise ImportError(
f"The filesystem for URL '{url}' is synchronous, and the required "
"AsyncFileSystemWrapper is not available. Upgrade fsspec to version "
"2024.12.0 or later to enable this functionality."
) from e

# fsspec is not consistent about removing the scheme from the path, so check and strip it here
# https://github.com/fsspec/filesystem_spec/issues/1722
Expand Down

0 comments on commit 4b8338f

Please sign in to comment.