Skip to content

Commit 6133bff

Browse files
committed
Fixes parsing of relative file:// URLs
Also fixes random mypy issues to get passt pre-commit hooks
1 parent ec2c359 commit 6133bff

4 files changed

Lines changed: 25 additions & 15 deletions

File tree

‎src/zarr/_cli/cli.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class CLIZarrFormatV3(StrEnum):
3535
v3 = "v3"
3636

3737

38-
@app.command() # type: ignore[untyped-decorator]
38+
@app.command()
3939
def migrate(
4040
zarr_format: Annotated[
4141
CLIZarrFormatV3,
@@ -120,7 +120,7 @@ def migrate(
120120
sync(migrate_metadata.remove_metadata(write_store, 2, force=False, dry_run=dry_run))
121121

122122

123-
@app.command() # type: ignore[untyped-decorator]
123+
@app.command()
124124
def remove_metadata(
125125
zarr_format: Annotated[
126126
CLIZarrFormat,
@@ -168,7 +168,7 @@ def remove_metadata(
168168
)
169169

170170

171-
@app.callback() # type: ignore[untyped-decorator]
171+
@app.callback()
172172
def main(
173173
verbose: Annotated[
174174
bool,

‎src/zarr/codecs/cast_value.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ def _do_cast(
345345
to_src = int if np.issubdtype(src_dtype, np.integer) else float
346346
to_tgt = int if np.issubdtype(target_dtype, np.integer) else float
347347
scalar_map_entries = {to_src(k): to_tgt(v) for k, v in scalar_map.items()}
348-
return cast_array_rs( # type: ignore[no-any-return]
348+
return cast_array_rs(
349349
arr,
350350
target_dtype=target_dtype,
351351
rounding_mode=self.rounding,

‎src/zarr/storage/_utils.py‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -90,16 +90,16 @@ def parse_store_url(url: str) -> ParsedStoreUrl:
9090

9191
parsed = urlparse(url)
9292

93-
# netloc is the "host" part (store name for memory://, bucket for s3://, etc.)
94-
name = parsed.netloc or None
93+
if parsed.scheme in ("file", ""):
94+
name = None
95+
path = url.removeprefix("file://")
96+
else:
97+
# netloc is the "host" part (store name for memory://, bucket for s3://, etc.)
98+
name = parsed.netloc or None
9599

96-
# For URLs with a scheme and netloc (like memory://store/path or s3://bucket/key),
97-
# strip the leading slash from the path component.
98-
# For local paths (no scheme), preserve the path as-is.
99-
if parsed.scheme and parsed.netloc:
100+
# For URLs with a non-file scheme and netloc (like memory://store/path or s3://bucket/key),
101+
# strip the leading slash from the path component.
100102
path = parsed.path.lstrip("/")
101-
else:
102-
path = parsed.path
103103

104104
return ParsedStoreUrl(scheme=parsed.scheme, name=name, path=path, raw=url)
105105

‎tests/test_store/test_utils.py‎

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,19 @@ def test_s3_url(self) -> None:
3939
scheme="s3", name="bucket", path="key", raw="s3://bucket/key"
4040
)
4141

42-
def test_file_url(self) -> None:
43-
result = parse_store_url("file:///tmp/test")
44-
assert result.scheme == "file"
42+
def test_absolute_file_url(self) -> None:
43+
url = "file:///something/absolute"
44+
result = parse_store_url(url)
45+
assert result == ParsedStoreUrl(
46+
scheme="file", name=None, path="/something/absolute", raw=url
47+
)
48+
49+
def test_relative_file_url(self) -> None:
50+
url = "file://something/relative"
51+
result = parse_store_url(url)
52+
assert result == ParsedStoreUrl(
53+
scheme="file", name=None, path="something/relative", raw=url
54+
)
4555

4656
def test_local_absolute_path(self) -> None:
4757
result = parse_store_url("/local/path")

0 commit comments

Comments
 (0)