From e9a9b12123885d9037e1e37644ecc63937b1931b Mon Sep 17 00:00:00 2001 From: Fredrik Jansson Date: Mon, 28 Jul 2025 13:53:17 +0200 Subject: [PATCH 1/2] Add exception for swift in fsspec path handling http(s) and swift filesystems need the scheme in the path. This commit adds a special case for the swift filesystem, when checking for the scheme presence. Also remove one if for the http(s) schemes. Here all schemes can call fs._strip_protocol(path). For the filesystems that need the scheme in the path, this function will not remove it. --- src/zarr/storage/_fsspec.py | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/zarr/storage/_fsspec.py b/src/zarr/storage/_fsspec.py index e169eededc..d5f8d888d7 100644 --- a/src/zarr/storage/_fsspec.py +++ b/src/zarr/storage/_fsspec.py @@ -139,8 +139,8 @@ def __init__( f"fs ({fs}) was not created with `asynchronous=True`, this may lead to surprising behavior", 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}://)") @@ -247,11 +247,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) From fd854f5a491e7c33811c47cfe4b917ca7be53c3d Mon Sep 17 00:00:00 2001 From: Fredrik Jansson Date: Tue, 29 Jul 2025 15:11:42 +0200 Subject: [PATCH 2/2] Add test for SWIFT store creation --- tests/test_store/test_fsspec.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/test_store/test_fsspec.py b/tests/test_store/test_fsspec.py index 026b25f8fc..d0518b7923 100644 --- a/tests/test_store/test_fsspec.py +++ b/tests/test_store/test_fsspec.py @@ -440,3 +440,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")