|
17 | 17 | ) |
18 | 18 | from zarr.errors import ContainsArrayAndGroupError, ContainsArrayError, ContainsGroupError |
19 | 19 | from zarr.storage._local import LocalStore |
20 | | -from zarr.storage._memory import MemoryStore |
| 20 | +from zarr.storage._memory import MemoryStore, _get_memory_store_from_url |
21 | 21 | from zarr.storage._utils import normalize_path |
22 | 22 |
|
23 | 23 | _has_fsspec = importlib.util.find_spec("fsspec") |
@@ -341,8 +341,20 @@ async def make_store( |
341 | 341 | return await LocalStore.open(root=store_like, mode=mode, read_only=_read_only) |
342 | 342 |
|
343 | 343 | elif isinstance(store_like, str): |
| 344 | + # Check for memory:// URLs first (in-process registry lookup) |
| 345 | + if store_like.startswith("memory://"): |
| 346 | + memory_store = _get_memory_store_from_url(store_like) |
| 347 | + if memory_store is not None: |
| 348 | + if _read_only and not memory_store.read_only: |
| 349 | + return memory_store.with_read_only(read_only=True) |
| 350 | + return memory_store |
| 351 | + # Memory store not found in registry - it may have been garbage collected |
| 352 | + raise ValueError( |
| 353 | + f"Memory store not found for URL '{store_like}'. " |
| 354 | + "The store may have been garbage collected." |
| 355 | + ) |
344 | 356 | # Either an FSSpec URI or a local filesystem path |
345 | | - if _is_fsspec_uri(store_like): |
| 357 | + elif _is_fsspec_uri(store_like): |
346 | 358 | return FsspecStore.from_url( |
347 | 359 | store_like, storage_options=storage_options, read_only=_read_only |
348 | 360 | ) |
@@ -418,6 +430,24 @@ async def make_store_path( |
418 | 430 | "'path' was provided but is not used for FSMap store_like objects. Specify the path when creating the FSMap instance instead." |
419 | 431 | ) |
420 | 432 |
|
| 433 | + elif isinstance(store_like, str) and store_like.startswith("memory://"): |
| 434 | + # Handle memory:// URLs specially - extract path from URL |
| 435 | + memory_store = _get_memory_store_from_url(store_like) |
| 436 | + if memory_store is None: |
| 437 | + raise ValueError( |
| 438 | + f"Memory store not found for URL '{store_like}'. " |
| 439 | + "The store may have been garbage collected." |
| 440 | + ) |
| 441 | + # Extract path from URL: "memory://123456/path/to/node" -> "path/to/node" |
| 442 | + url_without_scheme = store_like[len("memory://") :] |
| 443 | + parts = url_without_scheme.split("/", 1) |
| 444 | + url_path = parts[1] if len(parts) > 1 else "" |
| 445 | + # Combine URL path with any additional path argument |
| 446 | + combined_path = normalize_path(url_path) |
| 447 | + if path_normalized: |
| 448 | + combined_path = f"{combined_path}/{path_normalized}" if combined_path else path_normalized |
| 449 | + return await StorePath.open(memory_store, path=combined_path, mode=mode) |
| 450 | + |
421 | 451 | else: |
422 | 452 | store = await make_store(store_like, mode=mode, storage_options=storage_options) |
423 | 453 | return await StorePath.open(store, path=path_normalized, mode=mode) |
|
0 commit comments