diff --git a/src/zarr/storage/_fsspec.py b/src/zarr/storage/_fsspec.py index bbb934cc7d..5d9e0f2325 100644 --- a/src/zarr/storage/_fsspec.py +++ b/src/zarr/storage/_fsspec.py @@ -141,8 +141,8 @@ def __init__( category=ZarrUserWarning, stacklevel=2, ) - if "://" in path and not path.startswith("http"): - # `not path.startswith("http")` is a special case for the http filesystem (¯\_(ツ)_/¯) + if "://" in path and not path.startswith("http") and not path.startswith("swift"): + # special cases for the http(s) and swift filesystem, which need the protocol leaving in the path. scheme, _ = path.split("://", maxsplit=1) raise ValueError(f"path argument to FsspecStore must not include scheme ({scheme}://)") @@ -249,11 +249,7 @@ def from_url( if not fs.async_impl: fs = _make_async(fs) - # 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 - if "://" in path and not path.startswith("http"): - # `not path.startswith("http")` is a special case for the http filesystem (¯\_(ツ)_/¯) - path = fs._strip_protocol(path) + path = fs._strip_protocol(path) return cls(fs=fs, path=path, read_only=read_only, allowed_exceptions=allowed_exceptions) diff --git a/tests/test_store/test_fsspec.py b/tests/test_store/test_fsspec.py index 82a96b5d1e..880b90ec6e 100644 --- a/tests/test_store/test_fsspec.py +++ b/tests/test_store/test_fsspec.py @@ -441,3 +441,9 @@ async def test_with_read_only_auto_mkdir(tmp_path: Path) -> None: store_w = FsspecStore.from_url(f"file://{tmp_path}", storage_options={"auto_mkdir": False}) _ = store_w.with_read_only() + +def test_swift_store() -> None: + """ + Test creating an FsspecStore with a SWIFT URL. + """ + store = FsspecStore.from_url("swift://swift.dkrz.de/dkrz_xxx/testcontainer/test.zarr")