Skip to content

Commit 20a35f0

Browse files
committed
windows fix
1 parent 14c2817 commit 20a35f0

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

src/zarr/storage/_zep8.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
from __future__ import annotations
1010

11+
import re
1112
from typing import TYPE_CHECKING, Any
1213
from urllib.parse import urlparse
1314

@@ -83,6 +84,11 @@ def parse(self, url: str) -> list[URLSegment]:
8384

8485
return segments
8586

87+
@staticmethod
88+
def _is_windows_path(url: str) -> bool:
89+
r"""Check if URL is a Windows absolute path like C:\... or C:/..."""
90+
return re.match(r"^[A-Za-z]:[/\\]", url) is not None
91+
8692
@staticmethod
8793
def _parse_base_url(url: str) -> URLSegment:
8894
"""Parse the base URL component."""
@@ -94,6 +100,9 @@ def _parse_base_url(url: str) -> URLSegment:
94100
return URLSegment(scheme="file", path=parsed.path)
95101
else:
96102
return URLSegment(scheme=parsed.scheme, path=f"{parsed.netloc}{parsed.path}")
103+
elif URLParser._is_windows_path(url):
104+
# Windows absolute path like C:\... or C:/... - treat as filesystem path
105+
return URLSegment(scheme="file", path=url)
97106
elif ":" in url:
98107
# Adapter syntax like "memory:", "zip:path", etc.
99108
adapter, path = url.split(":", 1)

tests/test_store/test_zep8.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
Tests are organized by functionality groups rather than classes.
66
"""
77

8+
import tempfile
89
import zipfile
910
from pathlib import Path
1011
from typing import Any
@@ -1202,15 +1203,16 @@ async def test_filesystem_adapter_edge_cases() -> None:
12021203
store = await FileSystemAdapter.from_url_segment(segment, "file:")
12031204
assert store is not None
12041205

1205-
# Test with mode specified in kwargs
1206+
# Test with mode specified in kwargs - use cross-platform temp directory
1207+
temp_dir = tempfile.gettempdir()
12061208
segment = URLSegment(adapter="file")
1207-
store = await FileSystemAdapter.from_url_segment(segment, "file:/tmp", mode="r")
1209+
store = await FileSystemAdapter.from_url_segment(segment, f"file:{temp_dir}", mode="r")
12081210
assert store.read_only
12091211

12101212
# Test with read_only in storage_options
12111213
segment = URLSegment(adapter="file")
12121214
store = await FileSystemAdapter.from_url_segment(
1213-
segment, "file:/tmp", storage_options={"read_only": True}
1215+
segment, f"file:{temp_dir}", storage_options={"read_only": True}
12141216
)
12151217
assert store.read_only
12161218

0 commit comments

Comments
 (0)