1# SPDX-FileCopyrightText: Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved. 2# SPDX-License-Identifier: Apache-2.0 3# 4# Licensed under the Apache License, Version 2.0 (the "License"); 5# you may not use this file except in compliance with the License. 6# You may obtain a copy of the License at 7# 8# http://www.apache.org/licenses/LICENSE-2.0 9# 10# Unless required by applicable law or agreed to in writing, software 11# distributed under the License is distributed on an "AS IS" BASIS, 12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13# See the License for the specific language governing permissions and 14# limitations under the License. 15 16importos 17fromconcurrent.futuresimportThreadPoolExecutor,as_completed 18fromtypingimportTYPE_CHECKING,Any,Iterator,Mapping,Optional,Sequence,Tuple 19 20importzarras_zarr 21fromzarr.storageimportBaseStore 22 23from..shortcutsimportresolve_storage_client 24from..typesimportMSC_PROTOCOL 25 26ifTYPE_CHECKING: 27from..clientimportStorageClient 28 29
[docs] 30defopen_consolidated(*args:Any,**kwargs:Any)->_zarr.Group: 31""" 32 Adapt ``zarr.open_consolidated`` to use :py:class:`LazyZarrStore` when path matches the ``msc`` protocol. 33 34 If the path starts with the MSC protocol, it uses :py:class:`LazyZarrStore` with a resolved 35 storage client and prefix, passing ``msc_max_workers`` if provided. Otherwise, it 36 directly calls ``zarr.open_consolidated``. 37 """ 38args_list=list(args) 39path=args_list[0]ifargs_listelsekwargs.get("store") 40msc_max_workers=kwargs.pop("msc_max_workers",None) 41ifisinstance(path,str)andpath.startswith(MSC_PROTOCOL): 42storage_client,prefix=resolve_storage_client(path) 43zarr_store=LazyZarrStore(storage_client,prefix=prefix,msc_max_workers=msc_max_workers) 44ifpath==args_list[0]: 45args_list[0]=zarr_store 46else: 47kwargs["store"]=zarr_store 48return_zarr.open_consolidated(*args_list,**kwargs)# pyright: ignore [reportReturnType] 49return_zarr.open_consolidated(*args,**kwargs)# pyright: ignore [reportReturnType]