@@ -305,54 +305,60 @@ async def make_store(
305305 ------
306306 TypeError
307307 If the StoreLike object is not one of the supported types, or if storage_options is provided but not used.
308- ValueError
309- If storage_options is provided for a store that does not support it.
310308 """
311309 from zarr .storage ._fsspec import FsspecStore # circular import
312310
313- used_storage_options = False
314- assert mode in (None , "r" , "r+" , "a" , "w" , "w-" )
311+ if (
312+ not (isinstance (store_like , str ) and _is_fsspec_uri (store_like ))
313+ and storage_options is not None
314+ ):
315+ raise TypeError (
316+ "'storage_options' was provided but unused. "
317+ "'storage_options' is only used when the store is passed as a FSSpec URI string." ,
318+ )
315319
316- # if mode 'r' was provided, we'll open any new stores as read-only
320+ assert mode in ( None , "r" , "r+" , "a" , "w" , "w-" )
317321 _read_only = mode == "r"
318322
319323 if isinstance (store_like , StorePath ):
320- store = store_like .store
324+ # Already a StorePath
325+ return store_like .store
326+
321327 elif isinstance (store_like , Store ):
322- store = store_like
328+ # Already a Store
329+ return store_like
330+
331+ elif isinstance (store_like , dict ):
332+ # Already a dictionary that can be a MemoryStore
333+ #
334+ # We deliberate only consider dict[str, Buffer] here, and not arbitrary mutable mappings.
335+ # By only allowing dictionaries, which are in-memory, we know that MemoryStore appropriate.
336+ return await MemoryStore .open (store_dict = store_like , read_only = _read_only )
337+
323338 elif store_like is None :
324- store = await MemoryStore .open (read_only = _read_only )
339+ # Create a new in-memory store
340+ return await make_store ({}, mode = mode , storage_options = storage_options )
341+
325342 elif isinstance (store_like , Path ):
326- store = await LocalStore .open (root = store_like , read_only = _read_only )
327- elif isinstance (store_like , str ):
328- storage_options = storage_options or {}
343+ # Create a new LocalStore
344+ return await LocalStore .open (root = store_like , read_only = _read_only )
329345
346+ elif isinstance (store_like , str ):
347+ # Either a FSSpec URI or a local filesystem path
330348 if _is_fsspec_uri (store_like ):
331- used_storage_options = True
332- store = FsspecStore .from_url (
349+ return FsspecStore .from_url (
333350 store_like , storage_options = storage_options , read_only = _read_only
334351 )
335352 else :
336- store = await LocalStore .open (root = Path (store_like ), read_only = _read_only )
337- elif isinstance (store_like , dict ):
338- # We deliberate only consider dict[str, Buffer] here, and not arbitrary mutable mappings.
339- # By only allowing dictionaries, which are in-memory, we know that MemoryStore appropriate.
340- store = await MemoryStore .open (store_dict = store_like , read_only = _read_only )
353+ # Assume a filesystem path
354+ return await make_store (Path (store_like ), mode = mode , storage_options = storage_options )
355+
341356 elif _has_fsspec and isinstance (store_like , FSMap ):
342- if storage_options :
343- raise ValueError (
344- "'storage_options was provided but is not used for FSMap store_like objects. Specify the storage options when creating the FSMap instance instead."
345- )
346- store = FsspecStore .from_mapper (store_like , read_only = _read_only )
357+ return FsspecStore .from_mapper (store_like , read_only = _read_only )
358+
347359 else :
348360 raise TypeError (f"Unsupported type for store_like: '{ type (store_like ).__name__ } '" )
349361
350- if storage_options and not used_storage_options :
351- msg = "'storage_options' was provided but unused. 'storage_options' is only used for fsspec filesystem stores."
352- raise TypeError (msg )
353-
354- return store
355-
356362
357363async def make_store_path (
358364 store_like : StoreLike | None ,
@@ -391,7 +397,7 @@ async def make_store_path(
391397 TypeError
392398 If the StoreLike object is not one of the supported types, or if storage_options is provided but not used.
393399 ValueError
394- If storage_options is provided for a store that does not support it.
400+ If path is provided for a store that does not support it.
395401
396402 See Also
397403 --------
@@ -400,14 +406,19 @@ async def make_store_path(
400406 path_normalized = normalize_path (path )
401407
402408 if isinstance (store_like , StorePath ):
409+ # Already a StorePath
403410 if storage_options :
404- msg = "'storage_options' was provided but unused. 'storage_options' is only used for fsspec filesystem stores."
405- raise TypeError (msg )
411+ raise TypeError (
412+ "'storage_options' was provided but unused. "
413+ "'storage_options' is only used when the store is passed as a FSSpec URI string." ,
414+ )
406415 return store_like / path_normalized
416+
407417 elif _has_fsspec and isinstance (store_like , FSMap ) and path :
408418 raise ValueError (
409419 "'path' was provided but is not used for FSMap store_like objects. Specify the path when creating the FSMap instance instead."
410420 )
421+
411422 else :
412423 store = await make_store (store_like , mode = mode , storage_options = storage_options )
413424 return await StorePath .open (store , path = path_normalized , mode = mode )
0 commit comments