|
18 | 18 | from zarr.errors import ContainsArrayAndGroupError, ContainsArrayError, ContainsGroupError |
19 | 19 | from zarr.storage._local import LocalStore |
20 | 20 | from zarr.storage._memory import ManagedMemoryStore, MemoryStore |
21 | | -from zarr.storage._utils import normalize_path |
| 21 | +from zarr.storage._utils import _dereference_path, normalize_path |
22 | 22 |
|
23 | 23 | _has_fsspec = importlib.util.find_spec("fsspec") |
24 | 24 | if _has_fsspec: |
|
30 | 30 | from zarr.core.buffer import BufferPrototype |
31 | 31 |
|
32 | 32 |
|
33 | | -def _dereference_path(root: str, path: str) -> str: |
34 | | - if not isinstance(root, str): |
35 | | - msg = f"{root=} is not a string ({type(root)=})" # type: ignore[unreachable] |
36 | | - raise TypeError(msg) |
37 | | - if not isinstance(path, str): |
38 | | - msg = f"{path=} is not a string ({type(path)=})" # type: ignore[unreachable] |
39 | | - raise TypeError(msg) |
40 | | - root = root.rstrip("/") |
41 | | - path = f"{root}/{path}" if root else path |
42 | | - return path.rstrip("/") |
43 | | - |
44 | | - |
45 | 33 | class StorePath: |
46 | 34 | """ |
47 | 35 | Path-like interface for a Store. |
@@ -422,20 +410,11 @@ async def make_store_path( |
422 | 410 | ) |
423 | 411 |
|
424 | 412 | elif isinstance(store_like, str) and store_like.startswith("memory://"): |
425 | | - # Handle memory:// URLs specially - extract path from URL |
| 413 | + # Handle memory:// URLs specially |
| 414 | + # The store itself now handles the path from the URL |
426 | 415 | _read_only = mode == "r" |
427 | 416 | memory_store = ManagedMemoryStore.from_url(store_like, read_only=_read_only) |
428 | | - # Extract path from URL: "memory://123456/path/to/node" -> "path/to/node" |
429 | | - url_without_scheme = store_like[len("memory://") :] |
430 | | - parts = url_without_scheme.split("/", 1) |
431 | | - url_path = parts[1] if len(parts) > 1 else "" |
432 | | - # Combine URL path with any additional path argument |
433 | | - combined_path = normalize_path(url_path) |
434 | | - if path_normalized: |
435 | | - combined_path = ( |
436 | | - f"{combined_path}/{path_normalized}" if combined_path else path_normalized |
437 | | - ) |
438 | | - return await StorePath.open(memory_store, path=combined_path, mode=mode) |
| 417 | + return await StorePath.open(memory_store, path=path_normalized, mode=mode) |
439 | 418 |
|
440 | 419 | else: |
441 | 420 | store = await make_store(store_like, mode=mode, storage_options=storage_options) |
|
0 commit comments