Skip to content

Commit 27cf315

Browse files
authored
Add ZARR_V3_API_AVAILABLE environment variable (#1007)
* add ZARR_V3_API_AVAILABLE environment variable controls whether or not v3 stores are imported into the top-level zarr namespace * move StoreV3 implementations from storage.py to storage_v3.py * fix * move zarr/storage_v3.py to zarr/_storage/v3.py * Run Linux tests with ZARR_V3_API_AVAILABLE=1 defined * add # pragma nocover to environment-variable dependent branches * flake8 fix * fix outdated import path * fix mypy error
1 parent 07c8505 commit 27cf315

15 files changed

+686
-591
lines changed

.github/workflows/python-package.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ jobs:
6969
ZARR_TEST_ABS: 1
7070
ZARR_TEST_MONGO: 1
7171
ZARR_TEST_REDIS: 1
72+
ZARR_V3_API_AVAILABLE: 1
7273
run: |
7374
conda activate zarr-env
7475
mkdir ~/blob_emulator

zarr/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from zarr.errors import CopyError, MetadataError
1111
from zarr.hierarchy import Group, group, open_group
1212
from zarr.n5 import N5Store, N5FSStore
13+
from zarr._storage.store import v3_api_available
1314
from zarr.storage import (ABSStore, DBMStore, DictStore, DirectoryStore,
1415
KVStore, LMDBStore, LRUStoreCache, MemoryStore, MongoDBStore,
1516
NestedDirectoryStore, RedisStore, SQLiteStore,
@@ -19,3 +20,8 @@
1920

2021
# in case setuptools scm screw up and find version to be 0.0.0
2122
assert not __version__.startswith("0.0.0")
23+
24+
if v3_api_available:
25+
from zarr._storage.v3 import (ABSStoreV3, DBMStoreV3, KVStoreV3, DirectoryStoreV3,
26+
LMDBStoreV3, LRUStoreCacheV3, MemoryStoreV3, MongoDBStoreV3,
27+
RedisStoreV3, SQLiteStoreV3, ZipStoreV3)

zarr/_storage/store.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import abc
2+
import os
23
from collections.abc import MutableMapping
34
from string import ascii_letters, digits
45
from typing import Any, List, Mapping, Optional, Union
@@ -17,6 +18,8 @@
1718

1819
DEFAULT_ZARR_VERSION = 2
1920

21+
v3_api_available = os.environ.get('ZARR_V3_API_AVAILABLE', '0').lower() not in ['0', 'false']
22+
2023

2124
class BaseStore(MutableMapping):
2225
"""Abstract base class for store implementations.
@@ -261,7 +264,7 @@ def _ensure_store(store):
261264
262265
We'll do this conversion in a few places automatically
263266
"""
264-
from zarr.storage import KVStoreV3 # avoid circular import
267+
from zarr._storage.v3 import KVStoreV3 # avoid circular import
265268
if store is None:
266269
return None
267270
elif isinstance(store, StoreV3):

0 commit comments

Comments
 (0)