Skip to content

Commit 5201654

Browse files
committed
Allow a user-specified name for ManagedMemoryStore instances.
Ensure that `ManagedMemoryStore` names do not contain the separator character "/" Ensure that `ManagedMemoryStore` instances are tied the PID of the creating process
1 parent 64820a7 commit 5201654

5 files changed

Lines changed: 496 additions & 72 deletions

File tree

src/zarr/storage/_common.py

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
from zarr.errors import ContainsArrayAndGroupError, ContainsArrayError, ContainsGroupError
1919
from zarr.storage._local import LocalStore
2020
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
2222

2323
_has_fsspec = importlib.util.find_spec("fsspec")
2424
if _has_fsspec:
@@ -30,18 +30,6 @@
3030
from zarr.core.buffer import BufferPrototype
3131

3232

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-
4533
class StorePath:
4634
"""
4735
Path-like interface for a Store.
@@ -422,20 +410,11 @@ async def make_store_path(
422410
)
423411

424412
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
426415
_read_only = mode == "r"
427416
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)
439418

440419
else:
441420
store = await make_store(store_like, mode=mode, storage_options=storage_options)

src/zarr/storage/_fsspec.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
)
1717
from zarr.core.buffer import Buffer
1818
from zarr.errors import ZarrUserWarning
19-
from zarr.storage._common import _dereference_path
19+
from zarr.storage._common import _dereference_path # type: ignore[attr-defined]
2020

2121
if TYPE_CHECKING:
2222
from collections.abc import AsyncIterator, Iterable

0 commit comments

Comments
 (0)