From c1a753f9e8252c1c105ce186c3fdb9ae9364c8b4 Mon Sep 17 00:00:00 2001 From: Joseph Hamman Date: Fri, 9 Aug 2024 15:15:49 -0700 Subject: [PATCH 1/5] create core subpackage and move initial modules --- src/zarr/__init__.py | 6 ++--- src/zarr/abc/codec.py | 15 +++++++++++- src/zarr/abc/metadata.py | 3 +++ src/zarr/abc/store.py | 3 +++ src/zarr/api/asynchronous.py | 33 +++++++++++++++++++++++-- src/zarr/api/synchronous.py | 34 +++++++++++++++++++++++--- src/zarr/array_spec.py | 3 +++ src/zarr/attributes.py | 3 +++ src/zarr/chunk_grids.py | 2 +- src/zarr/codecs/pipeline.py | 4 +-- src/zarr/codecs/sharding.py | 8 +++++- src/zarr/core/__init__.py | 0 src/zarr/{ => core}/array.py | 17 +++++-------- src/zarr/{ => core}/config.py | 4 +++ src/zarr/{ => core}/group.py | 6 ++--- src/zarr/{ => core}/indexing.py | 0 src/zarr/{ => core}/sync.py | 5 +++- src/zarr/errors.py | 7 ++++++ src/zarr/metadata.py | 3 +-- src/zarr/registry.py | 2 +- src/zarr/strategies.py | 5 ++-- tests/v3/conftest.py | 3 +-- tests/v3/test_array.py | 3 +-- tests/v3/test_buffer.py | 2 +- tests/v3/test_codecs/test_blosc.py | 2 +- tests/v3/test_codecs/test_codecs.py | 5 ++-- tests/v3/test_codecs/test_endian.py | 2 +- tests/v3/test_codecs/test_gzip.py | 2 +- tests/v3/test_codecs/test_sharding.py | 2 +- tests/v3/test_codecs/test_transpose.py | 3 +-- tests/v3/test_codecs/test_zstd.py | 2 +- tests/v3/test_common.py | 2 +- tests/v3/test_config.py | 4 +-- tests/v3/test_group.py | 6 ++--- tests/v3/test_indexing.py | 2 +- tests/v3/test_store/test_remote.py | 2 +- tests/v3/test_sync.py | 2 +- tests/v3/test_v2.py | 2 +- 38 files changed, 150 insertions(+), 59 deletions(-) create mode 100644 src/zarr/core/__init__.py rename src/zarr/{ => core}/array.py (99%) rename src/zarr/{ => core}/config.py (96%) rename src/zarr/{ => core}/group.py (99%) rename src/zarr/{ => core}/indexing.py (100%) rename src/zarr/{ => core}/sync.py (98%) diff --git a/src/zarr/__init__.py b/src/zarr/__init__.py index 227b0cf63e..0259672f74 100644 --- a/src/zarr/__init__.py +++ b/src/zarr/__init__.py @@ -26,9 +26,9 @@ zeros, zeros_like, ) -from zarr.array import Array, AsyncArray -from zarr.config import config -from zarr.group import AsyncGroup, Group +from zarr.core.array import Array, AsyncArray +from zarr.core.config import config +from zarr.core.group import AsyncGroup, Group # in case setuptools scm screw up and find version to be 0.0.0 assert not __version__.startswith("0.0.0") diff --git a/src/zarr/abc/codec.py b/src/zarr/abc/codec.py index 9223019fab..92255760ed 100644 --- a/src/zarr/abc/codec.py +++ b/src/zarr/abc/codec.py @@ -11,7 +11,7 @@ from zarr.buffer import Buffer, NDBuffer from zarr.chunk_grids import ChunkGrid from zarr.common import ChunkCoords, concurrent_map -from zarr.config import config +from zarr.core.config import config if TYPE_CHECKING: from typing_extensions import Self @@ -421,3 +421,16 @@ async def wrap(chunk: CodecInput | None, chunk_spec: ArraySpec) -> CodecOutput | return await func(chunk, chunk_spec) return wrap + + +__all__ = [ + "CodecInput", + "CodecOutput", + "ArrayArrayCodec", + "ArrayBytesCodec", + "BytesBytesCodec", + "ArrayBytesCodecPartialDecodeMixin", + "ArrayBytesCodecPartialEncodeMixin", + "CodecPipeline", + # TODO: also include batching_helper and noop_for_none? +] diff --git a/src/zarr/abc/metadata.py b/src/zarr/abc/metadata.py index a14ffb8ce9..b7876072e5 100644 --- a/src/zarr/abc/metadata.py +++ b/src/zarr/abc/metadata.py @@ -44,3 +44,6 @@ def from_dict(cls, data: dict[str, JSON]) -> Self: ... return cls(**data) + + +__all__ = ["Metadata"] diff --git a/src/zarr/abc/store.py b/src/zarr/abc/store.py index 449816209b..78ed30dc70 100644 --- a/src/zarr/abc/store.py +++ b/src/zarr/abc/store.py @@ -245,3 +245,6 @@ async def set_or_delete(byte_setter: ByteSetter, value: Buffer | None) -> None: await byte_setter.delete() else: await byte_setter.set(value) + + +__all__ = ["Store", "AccessMode", "ByteGetter", "ByteSetter", "set_or_delete"] diff --git a/src/zarr/api/asynchronous.py b/src/zarr/api/asynchronous.py index 5d2e54baa3..1bafc1835f 100644 --- a/src/zarr/api/asynchronous.py +++ b/src/zarr/api/asynchronous.py @@ -9,11 +9,11 @@ import numpy.typing as npt from zarr.abc.codec import Codec -from zarr.array import Array, AsyncArray from zarr.buffer import NDArrayLike from zarr.chunk_key_encodings import ChunkKeyEncoding from zarr.common import JSON, AccessModeLiteral, ChunkCoords, MemoryOrder, ZarrFormat -from zarr.group import AsyncGroup +from zarr.core.array import Array, AsyncArray +from zarr.core.group import AsyncGroup from zarr.metadata import ArrayV2Metadata, ArrayV3Metadata from zarr.store import ( StoreLike, @@ -933,3 +933,32 @@ async def zeros_like(a: ArrayLike, **kwargs: Any) -> AsyncArray: """ like_kwargs = _like_args(a, kwargs) return await zeros(**like_kwargs) + + +__all__ = [ + "consolidate_metadata", + "copy", + "copy_all", + "copy_store", + "load", + "open", + "open_consolidated", + "save", + "save_array", + "save_group", + "tree", + "array", + "group", + "open_group", + "create", + "empty", + "empty_like", + "full", + "full_like", + "ones", + "ones_like", + "open_array", + "open_like", + "zeros", + "zeros_like", +] diff --git a/src/zarr/api/synchronous.py b/src/zarr/api/synchronous.py index eef87aab7e..b03029beb2 100644 --- a/src/zarr/api/synchronous.py +++ b/src/zarr/api/synchronous.py @@ -3,12 +3,12 @@ from typing import Any import zarr.api.asynchronous as async_api -from zarr.array import Array, AsyncArray from zarr.buffer import NDArrayLike from zarr.common import JSON, AccessModeLiteral, ChunkCoords, ZarrFormat -from zarr.group import Group +from zarr.core.array import Array, AsyncArray +from zarr.core.group import Group +from zarr.core.sync import sync from zarr.store import StoreLike -from zarr.sync import sync def consolidate_metadata(*args: Any, **kwargs: Any) -> Group: @@ -271,3 +271,31 @@ def zeros_like(a: async_api.ArrayLike, **kwargs: Any) -> Array: open_like.__doc__ = async_api.open_like.__doc__ zeros.__doc__ = async_api.zeros.__doc__ zeros_like.__doc__ = async_api.zeros_like.__doc__ + +__all__ = [ + "consolidate_metadata", + "copy", + "copy_all", + "copy_store", + "load", + "open", + "open_consolidated", + "save", + "save_array", + "save_group", + "tree", + "array", + "group", + "open_group", + "create", + "empty", + "empty_like", + "full", + "full_like", + "ones", + "ones_like", + "open_array", + "open_like", + "zeros", + "zeros_like", +] diff --git a/src/zarr/array_spec.py b/src/zarr/array_spec.py index d5717944b4..0ccdde009e 100644 --- a/src/zarr/array_spec.py +++ b/src/zarr/array_spec.py @@ -39,3 +39,6 @@ def __init__( @property def ndim(self) -> int: return len(self.shape) + + +__all__ = ["ArraySpec"] diff --git a/src/zarr/attributes.py b/src/zarr/attributes.py index 079ae38a33..4931907b8f 100644 --- a/src/zarr/attributes.py +++ b/src/zarr/attributes.py @@ -33,3 +33,6 @@ def __iter__(self) -> Iterator[str]: def __len__(self) -> int: return len(self._obj.metadata.attributes) + + +__all__ = ["Attributes"] diff --git a/src/zarr/chunk_grids.py b/src/zarr/chunk_grids.py index b494a3e5e8..0fbd1d588b 100644 --- a/src/zarr/chunk_grids.py +++ b/src/zarr/chunk_grids.py @@ -19,7 +19,7 @@ parse_named_configuration, parse_shapelike, ) -from zarr.indexing import ceildiv +from zarr.core.indexing import ceildiv if TYPE_CHECKING: from typing_extensions import Self diff --git a/src/zarr/codecs/pipeline.py b/src/zarr/codecs/pipeline.py index 8cda04c9ff..6ecf81422d 100644 --- a/src/zarr/codecs/pipeline.py +++ b/src/zarr/codecs/pipeline.py @@ -21,8 +21,8 @@ from zarr.buffer import Buffer, BufferPrototype, NDBuffer from zarr.chunk_grids import ChunkGrid from zarr.common import JSON, ChunkCoords, concurrent_map, parse_named_configuration -from zarr.config import config -from zarr.indexing import SelectorTuple, is_scalar, is_total_slice +from zarr.core.config import config +from zarr.core.indexing import SelectorTuple, is_scalar, is_total_slice from zarr.registry import get_codec_class, register_pipeline if TYPE_CHECKING: diff --git a/src/zarr/codecs/sharding.py b/src/zarr/codecs/sharding.py index ef8b80c02d..b366def71d 100644 --- a/src/zarr/codecs/sharding.py +++ b/src/zarr/codecs/sharding.py @@ -37,7 +37,13 @@ parse_shapelike, product, ) -from zarr.indexing import BasicIndexer, SelectorTuple, c_order_iter, get_indexer, morton_order_iter +from zarr.core.indexing import ( + BasicIndexer, + SelectorTuple, + c_order_iter, + get_indexer, + morton_order_iter, +) from zarr.metadata import parse_codecs from zarr.registry import get_ndbuffer_class, get_pipeline_class, register_codec diff --git a/src/zarr/core/__init__.py b/src/zarr/core/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/src/zarr/array.py b/src/zarr/core/array.py similarity index 99% rename from src/zarr/array.py rename to src/zarr/core/array.py index e41118805e..dbfe57691d 100644 --- a/src/zarr/array.py +++ b/src/zarr/core/array.py @@ -1,14 +1,6 @@ from __future__ import annotations import json - -# Notes on what I've changed here: -# 1. Split Array into AsyncArray and Array -# 3. Added .size and .attrs methods -# 4. Temporarily disabled the creation of ArrayV2 -# 5. Added from_dict to AsyncArray -# Questions to consider: -# 1. Was splitting the array into two classes really necessary? from asyncio import gather from collections.abc import Iterable from dataclasses import dataclass, field, replace @@ -35,8 +27,8 @@ concurrent_map, product, ) -from zarr.config import config, parse_indexing_order -from zarr.indexing import ( +from zarr.core.config import config, parse_indexing_order +from zarr.core.indexing import ( BasicIndexer, BasicSelection, BlockIndex, @@ -59,13 +51,13 @@ is_scalar, pop_fields, ) +from zarr.core.sync import sync from zarr.metadata import ArrayMetadata, ArrayV2Metadata, ArrayV3Metadata from zarr.registry import get_pipeline_class from zarr.store import StoreLike, StorePath, make_store_path from zarr.store.core import ( ensure_no_existing_node, ) -from zarr.sync import sync def parse_array_metadata(data: Any) -> ArrayV2Metadata | ArrayV3Metadata: @@ -2056,3 +2048,6 @@ def info(self) -> None: return sync( self._async_array.info(), ) + + +__all__ = ["Array", "AsyncArray"] diff --git a/src/zarr/config.py b/src/zarr/core/config.py similarity index 96% rename from src/zarr/config.py rename to src/zarr/core/config.py index ec78747a6b..3f4e91ba9a 100644 --- a/src/zarr/config.py +++ b/src/zarr/core/config.py @@ -72,3 +72,7 @@ def parse_indexing_order(data: Any) -> Literal["C", "F"]: return cast(Literal["C", "F"], data) msg = f"Expected one of ('C', 'F'), got {data} instead." raise ValueError(msg) + + +# TODO: why is parse_indexing_order here? +__all__ = ["config", "parse_indexing_order"] diff --git a/src/zarr/group.py b/src/zarr/core/group.py similarity index 99% rename from src/zarr/group.py rename to src/zarr/core/group.py index 432ebc4604..35d2638d53 100644 --- a/src/zarr/group.py +++ b/src/zarr/core/group.py @@ -13,7 +13,6 @@ from zarr.abc.codec import Codec from zarr.abc.metadata import Metadata from zarr.abc.store import set_or_delete -from zarr.array import Array, AsyncArray from zarr.attributes import Attributes from zarr.buffer import Buffer, BufferPrototype, default_buffer_prototype from zarr.chunk_key_encodings import ChunkKeyEncoding @@ -26,10 +25,11 @@ ChunkCoords, ZarrFormat, ) -from zarr.config import config +from zarr.core.array import Array, AsyncArray +from zarr.core.config import config +from zarr.core.sync import SyncMixin, sync from zarr.store import StoreLike, StorePath, make_store_path from zarr.store.core import ensure_no_existing_node -from zarr.sync import SyncMixin, sync if TYPE_CHECKING: from collections.abc import AsyncGenerator, Iterable diff --git a/src/zarr/indexing.py b/src/zarr/core/indexing.py similarity index 100% rename from src/zarr/indexing.py rename to src/zarr/core/indexing.py diff --git a/src/zarr/sync.py b/src/zarr/core/sync.py similarity index 98% rename from src/zarr/sync.py rename to src/zarr/core/sync.py index 8af14f602e..3467e1f149 100644 --- a/src/zarr/sync.py +++ b/src/zarr/core/sync.py @@ -12,7 +12,7 @@ from typing_extensions import ParamSpec -from zarr.config import config +from zarr.core.config import config P = ParamSpec("P") T = TypeVar("T") @@ -128,3 +128,6 @@ async def iter_to_list() -> list[T]: return [item async for item in async_iterator] return self._sync(iter_to_list()) + + +__all__ = ["sync", "SyncMixin"] diff --git a/src/zarr/errors.py b/src/zarr/errors.py index 140229b2eb..f6321e474b 100644 --- a/src/zarr/errors.py +++ b/src/zarr/errors.py @@ -23,3 +23,10 @@ class ContainsArrayAndGroupError(_BaseZarrError): "Only one of these files may be present in a given directory / prefix. " "Remove the .zarray file, or the .zgroup file, or both." ) + + +__all__ = [ + "ContainsGroupError", + "ContainsArrayError", + "ContainsArrayAndGroupError", +] diff --git a/src/zarr/metadata.py b/src/zarr/metadata.py index e801a6f966..cc40e8dc62 100644 --- a/src/zarr/metadata.py +++ b/src/zarr/metadata.py @@ -15,7 +15,6 @@ from zarr.buffer import Buffer, BufferPrototype, default_buffer_prototype from zarr.chunk_grids import ChunkGrid, RegularChunkGrid from zarr.chunk_key_encodings import ChunkKeyEncoding, parse_separator -from zarr.config import config from zarr.registry import get_codec_class, get_pipeline_class if TYPE_CHECKING: @@ -35,7 +34,7 @@ parse_named_configuration, parse_shapelike, ) -from zarr.config import parse_indexing_order +from zarr.core.config import config, parse_indexing_order # For type checking _bool = bool diff --git a/src/zarr/registry.py b/src/zarr/registry.py index ac373f401d..095d24b51d 100644 --- a/src/zarr/registry.py +++ b/src/zarr/registry.py @@ -11,7 +11,7 @@ from importlib.metadata import EntryPoint from importlib.metadata import entry_points as get_entry_points -from zarr.config import BadConfigError, config +from zarr.core.config import BadConfigError, config T = TypeVar("T") diff --git a/src/zarr/strategies.py b/src/zarr/strategies.py index 91a8542ce9..bfd83e1e51 100644 --- a/src/zarr/strategies.py +++ b/src/zarr/strategies.py @@ -5,9 +5,8 @@ import numpy as np from hypothesis import given, settings # noqa -from .array import Array -from .group import Group -from .store import MemoryStore, StoreLike +from zarr import Array, Group +from zarr.store import MemoryStore, StoreLike # Copied from Xarray _attr_keys = st.text(st.characters(), min_size=1) diff --git a/tests/v3/conftest.py b/tests/v3/conftest.py index 0a672d1f2e..74d50a071d 100644 --- a/tests/v3/conftest.py +++ b/tests/v3/conftest.py @@ -6,10 +6,9 @@ from _pytest.compat import LEGACY_PATH -from zarr import config +from zarr import AsyncGroup, config from zarr.abc.store import Store from zarr.common import ChunkCoords, MemoryOrder, ZarrFormat -from zarr.group import AsyncGroup if TYPE_CHECKING: from typing import Any, Literal diff --git a/tests/v3/test_array.py b/tests/v3/test_array.py index 9fd135ad5c..64305c256b 100644 --- a/tests/v3/test_array.py +++ b/tests/v3/test_array.py @@ -3,10 +3,9 @@ import numpy as np import pytest -from zarr.array import Array +from zarr import Array, Group from zarr.common import ZarrFormat from zarr.errors import ContainsArrayError, ContainsGroupError -from zarr.group import Group from zarr.store import LocalStore, MemoryStore from zarr.store.core import StorePath diff --git a/tests/v3/test_buffer.py b/tests/v3/test_buffer.py index d53e98d42d..8fbbfb8038 100644 --- a/tests/v3/test_buffer.py +++ b/tests/v3/test_buffer.py @@ -3,7 +3,7 @@ import numpy as np import pytest -from zarr.array import AsyncArray +from zarr import AsyncArray from zarr.buffer import ArrayLike, BufferPrototype, NDArrayLike, numpy_buffer_prototype from zarr.codecs.blosc import BloscCodec from zarr.codecs.bytes import BytesCodec diff --git a/tests/v3/test_codecs/test_blosc.py b/tests/v3/test_codecs/test_blosc.py index 33ca9eba77..814db11a57 100644 --- a/tests/v3/test_codecs/test_blosc.py +++ b/tests/v3/test_codecs/test_blosc.py @@ -3,8 +3,8 @@ import numpy as np import pytest +from zarr import AsyncArray from zarr.abc.store import Store -from zarr.array import AsyncArray from zarr.buffer import default_buffer_prototype from zarr.codecs import BloscCodec, BytesCodec, ShardingCodec from zarr.store.core import StorePath diff --git a/tests/v3/test_codecs/test_codecs.py b/tests/v3/test_codecs/test_codecs.py index a2b459f60d..d95526fab7 100644 --- a/tests/v3/test_codecs/test_codecs.py +++ b/tests/v3/test_codecs/test_codecs.py @@ -7,9 +7,9 @@ import pytest import zarr.v2 +from zarr import Array, AsyncArray, config from zarr.abc.codec import Codec from zarr.abc.store import Store -from zarr.array import Array, AsyncArray from zarr.buffer import default_buffer_prototype from zarr.codecs import ( BytesCodec, @@ -18,8 +18,7 @@ TransposeCodec, ) from zarr.common import MemoryOrder -from zarr.config import config -from zarr.indexing import Selection, morton_order_iter +from zarr.core.indexing import Selection, morton_order_iter from zarr.store import StorePath from zarr.testing.utils import assert_bytes_equal diff --git a/tests/v3/test_codecs/test_endian.py b/tests/v3/test_codecs/test_endian.py index 6f3e1c9482..a9ebbf700f 100644 --- a/tests/v3/test_codecs/test_endian.py +++ b/tests/v3/test_codecs/test_endian.py @@ -4,8 +4,8 @@ import pytest import zarr.v2 +from zarr import AsyncArray from zarr.abc.store import Store -from zarr.array import AsyncArray from zarr.buffer import default_buffer_prototype from zarr.codecs import BytesCodec from zarr.store.core import StorePath diff --git a/tests/v3/test_codecs/test_gzip.py b/tests/v3/test_codecs/test_gzip.py index f982bacb87..3d33d885fc 100644 --- a/tests/v3/test_codecs/test_gzip.py +++ b/tests/v3/test_codecs/test_gzip.py @@ -1,8 +1,8 @@ import numpy as np import pytest +from zarr import Array from zarr.abc.store import Store -from zarr.array import Array from zarr.codecs import BytesCodec, GzipCodec from zarr.store.core import StorePath diff --git a/tests/v3/test_codecs/test_sharding.py b/tests/v3/test_codecs/test_sharding.py index 27667ca9dd..ed338f0ec1 100644 --- a/tests/v3/test_codecs/test_sharding.py +++ b/tests/v3/test_codecs/test_sharding.py @@ -3,8 +3,8 @@ import numpy as np import pytest +from zarr import Array, AsyncArray from zarr.abc.store import Store -from zarr.array import Array, AsyncArray from zarr.buffer import default_buffer_prototype from zarr.codecs import ( BloscCodec, diff --git a/tests/v3/test_codecs/test_transpose.py b/tests/v3/test_codecs/test_transpose.py index bea7435122..b3cedd2b68 100644 --- a/tests/v3/test_codecs/test_transpose.py +++ b/tests/v3/test_codecs/test_transpose.py @@ -2,13 +2,12 @@ import pytest import zarr.v2 +from zarr import Array, AsyncArray, config from zarr.abc.codec import Codec from zarr.abc.store import Store -from zarr.array import Array, AsyncArray from zarr.buffer import default_buffer_prototype from zarr.codecs import BytesCodec, ShardingCodec, TransposeCodec from zarr.common import MemoryOrder -from zarr.config import config from zarr.store.core import StorePath from .test_codecs import _AsyncArrayProxy diff --git a/tests/v3/test_codecs/test_zstd.py b/tests/v3/test_codecs/test_zstd.py index 1e1b1e02c9..8b8b71842d 100644 --- a/tests/v3/test_codecs/test_zstd.py +++ b/tests/v3/test_codecs/test_zstd.py @@ -1,8 +1,8 @@ import numpy as np import pytest +from zarr import Array from zarr.abc.store import Store -from zarr.array import Array from zarr.codecs import BytesCodec, ZstdCodec from zarr.store.core import StorePath diff --git a/tests/v3/test_common.py b/tests/v3/test_common.py index bb59789843..7f731cde52 100644 --- a/tests/v3/test_common.py +++ b/tests/v3/test_common.py @@ -10,7 +10,7 @@ import pytest from zarr.common import parse_name, parse_shapelike, product -from zarr.config import parse_indexing_order +from zarr.core.config import parse_indexing_order @pytest.mark.parametrize("data", [(0, 0, 0, 0), (1, 3, 4, 5, 6), (2, 4)]) diff --git a/tests/v3/test_config.py b/tests/v3/test_config.py index 8e7b868520..6d9713366f 100644 --- a/tests/v3/test_config.py +++ b/tests/v3/test_config.py @@ -14,8 +14,8 @@ from zarr.array_spec import ArraySpec from zarr.buffer import NDBuffer from zarr.codecs import BatchedCodecPipeline, BloscCodec, BytesCodec, Crc32cCodec, ShardingCodec -from zarr.config import BadConfigError, config -from zarr.indexing import SelectorTuple +from zarr.core.config import BadConfigError, config +from zarr.core.indexing import SelectorTuple from zarr.registry import ( fully_qualified_name, get_buffer_class, diff --git a/tests/v3/test_group.py b/tests/v3/test_group.py index daa5979b27..6191ddf7f6 100644 --- a/tests/v3/test_group.py +++ b/tests/v3/test_group.py @@ -6,14 +6,14 @@ import pytest from _pytest.compat import LEGACY_PATH -from zarr.array import Array, AsyncArray +from zarr import Array, AsyncArray, AsyncGroup, Group from zarr.buffer import Buffer from zarr.common import ZarrFormat +from zarr.core.group import GroupMetadata +from zarr.core.sync import sync from zarr.errors import ContainsArrayError, ContainsGroupError -from zarr.group import AsyncGroup, Group, GroupMetadata from zarr.store import LocalStore, MemoryStore, StorePath from zarr.store.core import make_store_path -from zarr.sync import sync from .conftest import parse_store diff --git a/tests/v3/test_indexing.py b/tests/v3/test_indexing.py index 12547765a9..982dfc5037 100644 --- a/tests/v3/test_indexing.py +++ b/tests/v3/test_indexing.py @@ -14,7 +14,7 @@ from zarr.abc.store import Store from zarr.buffer import BufferPrototype, NDBuffer from zarr.common import ChunkCoords -from zarr.indexing import ( +from zarr.core.indexing import ( make_slice_selection, normalize_integer_selection, oindex, diff --git a/tests/v3/test_store/test_remote.py b/tests/v3/test_store/test_remote.py index be9fa5ef67..0ce89ab503 100644 --- a/tests/v3/test_store/test_remote.py +++ b/tests/v3/test_store/test_remote.py @@ -5,8 +5,8 @@ from upath import UPath from zarr.buffer import Buffer, default_buffer_prototype +from zarr.core.sync import sync from zarr.store import RemoteStore -from zarr.sync import sync from zarr.testing.store import StoreTests s3fs = pytest.importorskip("s3fs") diff --git a/tests/v3/test_sync.py b/tests/v3/test_sync.py index 7e3b8dd111..a335f9b48c 100644 --- a/tests/v3/test_sync.py +++ b/tests/v3/test_sync.py @@ -4,7 +4,7 @@ import pytest -from zarr.sync import SyncError, SyncMixin, _get_lock, _get_loop, sync +from zarr.core.sync import SyncError, SyncMixin, _get_lock, _get_loop, sync @pytest.fixture(params=[True, False]) diff --git a/tests/v3/test_v2.py b/tests/v3/test_v2.py index 7a7d728067..4f4dc5aed3 100644 --- a/tests/v3/test_v2.py +++ b/tests/v3/test_v2.py @@ -3,8 +3,8 @@ import numpy as np import pytest +from zarr import Array from zarr.abc.store import Store -from zarr.array import Array from zarr.store import MemoryStore, StorePath From 240494eea790bd80a6ef33609fae5e83798637bb Mon Sep 17 00:00:00 2001 From: Joseph Hamman Date: Mon, 12 Aug 2024 13:51:37 -0700 Subject: [PATCH 2/5] rev 2 --- src/zarr/abc/codec.py | 23 +++++++-------- src/zarr/abc/metadata.py | 2 +- src/zarr/abc/store.py | 4 +-- src/zarr/api/asynchronous.py | 8 +++--- src/zarr/api/synchronous.py | 4 +-- src/zarr/codecs/_v2.py | 6 ++-- src/zarr/codecs/blosc.py | 6 ++-- src/zarr/codecs/bytes.py | 6 ++-- src/zarr/codecs/crc32c_.py | 6 ++-- src/zarr/codecs/gzip.py | 6 ++-- src/zarr/codecs/pipeline.py | 8 +++--- src/zarr/codecs/sharding.py | 16 +++++------ src/zarr/codecs/transpose.py | 8 +++--- src/zarr/codecs/zstd.py | 6 ++-- src/zarr/convenience.py | 28 ------------------ src/zarr/core/array.py | 21 +++++++------- src/zarr/{ => core}/array_spec.py | 12 ++++---- src/zarr/{ => core}/attributes.py | 13 ++++----- src/zarr/{ => core}/buffer.py | 4 +-- src/zarr/{ => core}/chunk_grids.py | 2 +- src/zarr/{ => core}/chunk_key_encodings.py | 2 +- src/zarr/{ => core}/common.py | 0 src/zarr/core/config.py | 8 ++---- src/zarr/core/group.py | 14 +++++---- src/zarr/core/indexing.py | 11 +++---- src/zarr/{ => core}/metadata.py | 10 +++---- src/zarr/core/sync.py | 14 ++++----- src/zarr/creation.py | 30 -------------------- src/zarr/registry.py | 25 ++++++++++++---- src/zarr/store/__init__.py | 8 +++--- src/zarr/store/{local.py => _local.py} | 9 ++++-- src/zarr/store/{memory.py => _memory.py} | 11 +++++-- src/zarr/store/{remote.py => _remote.py} | 9 +++--- src/zarr/store/{utils.py => _utils.py} | 2 +- src/zarr/store/{core.py => common.py} | 14 +++++---- src/zarr/testing/__init__.py | 6 +++- src/zarr/testing/buffer.py | 9 +++++- src/zarr/testing/store.py | 7 +++-- src/zarr/testing/utils.py | 7 +++-- tests/v3/conftest.py | 4 +-- tests/v3/package_with_entrypoint/__init__.py | 6 ++-- tests/v3/test_array.py | 4 +-- tests/v3/test_buffer.py | 4 +-- tests/v3/test_chunk_grids.py | 2 +- tests/v3/test_codecs/test_blosc.py | 4 +-- tests/v3/test_codecs/test_codecs.py | 4 +-- tests/v3/test_codecs/test_endian.py | 4 +-- tests/v3/test_codecs/test_gzip.py | 2 +- tests/v3/test_codecs/test_sharding.py | 4 +-- tests/v3/test_codecs/test_transpose.py | 6 ++-- tests/v3/test_codecs/test_zstd.py | 2 +- tests/v3/test_common.py | 2 +- tests/v3/test_config.py | 8 +++--- tests/v3/test_group.py | 6 ++-- tests/v3/test_indexing.py | 8 +++--- tests/v3/test_metadata/test_v2.py | 2 +- tests/v3/test_metadata/test_v3.py | 8 +++--- tests/v3/test_store/test_core.py | 6 ++-- tests/v3/test_store/test_local.py | 4 +-- tests/v3/test_store/test_memory.py | 4 +-- tests/v3/test_store/test_remote.py | 2 +- 61 files changed, 230 insertions(+), 251 deletions(-) rename src/zarr/{ => core}/array_spec.py (80%) rename src/zarr/{ => core}/attributes.py (82%) rename src/zarr/{ => core}/buffer.py (99%) rename src/zarr/{ => core}/chunk_grids.py (99%) rename src/zarr/{ => core}/chunk_key_encodings.py (98%) rename src/zarr/{ => core}/common.py (100%) rename src/zarr/{ => core}/metadata.py (98%) rename src/zarr/store/{local.py => _local.py} (96%) rename src/zarr/store/{memory.py => _memory.py} (92%) rename src/zarr/store/{remote.py => _remote.py} (97%) rename src/zarr/store/{utils.py => _utils.py} (94%) rename src/zarr/store/{core.py => common.py} (95%) diff --git a/src/zarr/abc/codec.py b/src/zarr/abc/codec.py index 92255760ed..e15c278bca 100644 --- a/src/zarr/abc/codec.py +++ b/src/zarr/abc/codec.py @@ -8,17 +8,17 @@ from zarr.abc.metadata import Metadata from zarr.abc.store import ByteGetter, ByteSetter -from zarr.buffer import Buffer, NDBuffer -from zarr.chunk_grids import ChunkGrid -from zarr.common import ChunkCoords, concurrent_map +from zarr.core.buffer import Buffer, NDBuffer +from zarr.core.chunk_grids import ChunkGrid +from zarr.core.common import ChunkCoords, concurrent_map from zarr.core.config import config if TYPE_CHECKING: from typing_extensions import Self - from zarr.array_spec import ArraySpec - from zarr.common import JSON - from zarr.indexing import SelectorTuple + from zarr.core.array_spec import ArraySpec + from zarr.core.common import JSON + from zarr.core.indexing import SelectorTuple CodecInput = TypeVar("CodecInput", bound=NDBuffer | Buffer) CodecOutput = TypeVar("CodecOutput", bound=NDBuffer | Buffer) @@ -112,7 +112,7 @@ async def decode( ------- Iterable[CodecInput | None] """ - return await batching_helper(self._decode_single, chunks_and_specs) + return await _batching_helper(self._decode_single, chunks_and_specs) async def _encode_single( self, chunk_data: CodecInput, chunk_spec: ArraySpec @@ -135,7 +135,7 @@ async def encode( ------- Iterable[CodecOutput | None] """ - return await batching_helper(self._encode_single, chunks_and_specs) + return await _batching_helper(self._encode_single, chunks_and_specs) class ArrayArrayCodec(_Codec[NDBuffer, NDBuffer]): @@ -401,18 +401,18 @@ def from_dict(cls, data: Iterable[JSON | Codec]) -> Self: return cls(**data) -async def batching_helper( +async def _batching_helper( func: Callable[[CodecInput, ArraySpec], Awaitable[CodecOutput | None]], batch_info: Iterable[tuple[CodecInput | None, ArraySpec]], ) -> list[CodecOutput | None]: return await concurrent_map( list(batch_info), - noop_for_none(func), + _noop_for_none(func), config.get("async.concurrency"), ) -def noop_for_none( +def _noop_for_none( func: Callable[[CodecInput, ArraySpec], Awaitable[CodecOutput | None]], ) -> Callable[[CodecInput | None, ArraySpec], Awaitable[CodecOutput | None]]: async def wrap(chunk: CodecInput | None, chunk_spec: ArraySpec) -> CodecOutput | None: @@ -432,5 +432,4 @@ async def wrap(chunk: CodecInput | None, chunk_spec: ArraySpec) -> CodecOutput | "ArrayBytesCodecPartialDecodeMixin", "ArrayBytesCodecPartialEncodeMixin", "CodecPipeline", - # TODO: also include batching_helper and noop_for_none? ] diff --git a/src/zarr/abc/metadata.py b/src/zarr/abc/metadata.py index b7876072e5..9cdadddb9e 100644 --- a/src/zarr/abc/metadata.py +++ b/src/zarr/abc/metadata.py @@ -8,7 +8,7 @@ from dataclasses import dataclass, fields -from zarr.common import JSON +from zarr.core.common import JSON @dataclass(frozen=True) diff --git a/src/zarr/abc/store.py b/src/zarr/abc/store.py index 78ed30dc70..ae9b25cb7d 100644 --- a/src/zarr/abc/store.py +++ b/src/zarr/abc/store.py @@ -4,8 +4,8 @@ from typing_extensions import Self -from zarr.buffer import Buffer, BufferPrototype -from zarr.common import AccessModeLiteral, BytesLike +from zarr.core.buffer import Buffer, BufferPrototype +from zarr.core.common import AccessModeLiteral, BytesLike class AccessMode(NamedTuple): diff --git a/src/zarr/api/asynchronous.py b/src/zarr/api/asynchronous.py index 8571a7f88d..d47d30ca1c 100644 --- a/src/zarr/api/asynchronous.py +++ b/src/zarr/api/asynchronous.py @@ -9,12 +9,12 @@ import numpy.typing as npt from zarr.abc.codec import Codec -from zarr.buffer import NDArrayLike -from zarr.chunk_key_encodings import ChunkKeyEncoding -from zarr.common import JSON, AccessModeLiteral, ChunkCoords, MemoryOrder, ZarrFormat from zarr.core.array import Array, AsyncArray +from zarr.core.buffer import NDArrayLike +from zarr.core.chunk_key_encodings import ChunkKeyEncoding +from zarr.core.common import JSON, AccessModeLiteral, ChunkCoords, MemoryOrder, ZarrFormat from zarr.core.group import AsyncGroup -from zarr.metadata import ArrayV2Metadata, ArrayV3Metadata +from zarr.core.metadata import ArrayV2Metadata, ArrayV3Metadata from zarr.store import ( StoreLike, make_store_path, diff --git a/src/zarr/api/synchronous.py b/src/zarr/api/synchronous.py index b03029beb2..78621e5d1e 100644 --- a/src/zarr/api/synchronous.py +++ b/src/zarr/api/synchronous.py @@ -3,9 +3,9 @@ from typing import Any import zarr.api.asynchronous as async_api -from zarr.buffer import NDArrayLike -from zarr.common import JSON, AccessModeLiteral, ChunkCoords, ZarrFormat from zarr.core.array import Array, AsyncArray +from zarr.core.buffer import NDArrayLike +from zarr.core.common import JSON, AccessModeLiteral, ChunkCoords, ZarrFormat from zarr.core.group import Group from zarr.core.sync import sync from zarr.store import StoreLike diff --git a/src/zarr/codecs/_v2.py b/src/zarr/codecs/_v2.py index 60854bee34..3dc5c8e4a7 100644 --- a/src/zarr/codecs/_v2.py +++ b/src/zarr/codecs/_v2.py @@ -6,9 +6,9 @@ from numcodecs.compat import ensure_bytes, ensure_ndarray from zarr.abc.codec import ArrayArrayCodec, ArrayBytesCodec -from zarr.array_spec import ArraySpec -from zarr.buffer import Buffer, NDBuffer, default_buffer_prototype -from zarr.common import JSON, to_thread +from zarr.core.array_spec import ArraySpec +from zarr.core.buffer import Buffer, NDBuffer, default_buffer_prototype +from zarr.core.common import JSON, to_thread from zarr.registry import get_ndbuffer_class diff --git a/src/zarr/codecs/blosc.py b/src/zarr/codecs/blosc.py index d03ecbcbf2..8e01524992 100644 --- a/src/zarr/codecs/blosc.py +++ b/src/zarr/codecs/blosc.py @@ -9,9 +9,9 @@ from numcodecs.blosc import Blosc from zarr.abc.codec import BytesBytesCodec -from zarr.array_spec import ArraySpec -from zarr.buffer import Buffer, as_numpy_array_wrapper -from zarr.common import JSON, parse_enum, parse_named_configuration, to_thread +from zarr.core.array_spec import ArraySpec +from zarr.core.buffer import Buffer, as_numpy_array_wrapper +from zarr.core.common import JSON, parse_enum, parse_named_configuration, to_thread from zarr.registry import register_codec if TYPE_CHECKING: diff --git a/src/zarr/codecs/bytes.py b/src/zarr/codecs/bytes.py index 1fe9d900eb..c2ef0ee4f6 100644 --- a/src/zarr/codecs/bytes.py +++ b/src/zarr/codecs/bytes.py @@ -8,9 +8,9 @@ import numpy as np from zarr.abc.codec import ArrayBytesCodec -from zarr.array_spec import ArraySpec -from zarr.buffer import Buffer, NDArrayLike, NDBuffer -from zarr.common import JSON, parse_enum, parse_named_configuration +from zarr.core.array_spec import ArraySpec +from zarr.core.buffer import Buffer, NDArrayLike, NDBuffer +from zarr.core.common import JSON, parse_enum, parse_named_configuration from zarr.registry import register_codec if TYPE_CHECKING: diff --git a/src/zarr/codecs/crc32c_.py b/src/zarr/codecs/crc32c_.py index 5c94558b00..d40b95ef0c 100644 --- a/src/zarr/codecs/crc32c_.py +++ b/src/zarr/codecs/crc32c_.py @@ -7,9 +7,9 @@ from crc32c import crc32c from zarr.abc.codec import BytesBytesCodec -from zarr.array_spec import ArraySpec -from zarr.buffer import Buffer -from zarr.common import JSON, parse_named_configuration +from zarr.core.array_spec import ArraySpec +from zarr.core.buffer import Buffer +from zarr.core.common import JSON, parse_named_configuration from zarr.registry import register_codec if TYPE_CHECKING: diff --git a/src/zarr/codecs/gzip.py b/src/zarr/codecs/gzip.py index 915ae79832..bab81a104b 100644 --- a/src/zarr/codecs/gzip.py +++ b/src/zarr/codecs/gzip.py @@ -6,9 +6,9 @@ from numcodecs.gzip import GZip from zarr.abc.codec import BytesBytesCodec -from zarr.array_spec import ArraySpec -from zarr.buffer import Buffer, as_numpy_array_wrapper -from zarr.common import JSON, parse_named_configuration, to_thread +from zarr.core.array_spec import ArraySpec +from zarr.core.buffer import Buffer, as_numpy_array_wrapper +from zarr.core.common import JSON, parse_named_configuration, to_thread from zarr.registry import register_codec if TYPE_CHECKING: diff --git a/src/zarr/codecs/pipeline.py b/src/zarr/codecs/pipeline.py index 659b955c20..9c615d3d2c 100644 --- a/src/zarr/codecs/pipeline.py +++ b/src/zarr/codecs/pipeline.py @@ -18,9 +18,9 @@ CodecPipeline, ) from zarr.abc.store import ByteGetter, ByteSetter -from zarr.buffer import Buffer, BufferPrototype, NDBuffer -from zarr.chunk_grids import ChunkGrid -from zarr.common import JSON, ChunkCoords, concurrent_map, parse_named_configuration +from zarr.core.buffer import Buffer, BufferPrototype, NDBuffer +from zarr.core.chunk_grids import ChunkGrid +from zarr.core.common import JSON, ChunkCoords, concurrent_map, parse_named_configuration from zarr.core.config import config from zarr.core.indexing import SelectorTuple, is_scalar, is_total_slice from zarr.registry import get_codec_class, register_pipeline @@ -28,7 +28,7 @@ if TYPE_CHECKING: from typing_extensions import Self - from zarr.array_spec import ArraySpec + from zarr.core.array_spec import ArraySpec T = TypeVar("T") U = TypeVar("U") diff --git a/src/zarr/codecs/sharding.py b/src/zarr/codecs/sharding.py index 0423b9248c..fa706f57c7 100644 --- a/src/zarr/codecs/sharding.py +++ b/src/zarr/codecs/sharding.py @@ -18,18 +18,18 @@ CodecPipeline, ) from zarr.abc.store import ByteGetter, ByteSetter -from zarr.array_spec import ArraySpec -from zarr.buffer import ( +from zarr.codecs.bytes import BytesCodec +from zarr.codecs.crc32c_ import Crc32cCodec +from zarr.core.array_spec import ArraySpec +from zarr.core.buffer import ( Buffer, BufferPrototype, NDBuffer, default_buffer_prototype, numpy_buffer_prototype, ) -from zarr.chunk_grids import ChunkGrid, RegularChunkGrid -from zarr.codecs.bytes import BytesCodec -from zarr.codecs.crc32c_ import Crc32cCodec -from zarr.common import ( +from zarr.core.chunk_grids import ChunkGrid, RegularChunkGrid +from zarr.core.common import ( ChunkCoords, ChunkCoordsLike, parse_enum, @@ -44,7 +44,7 @@ get_indexer, morton_order_iter, ) -from zarr.metadata import parse_codecs +from zarr.core.metadata import parse_codecs from zarr.registry import get_ndbuffer_class, get_pipeline_class, register_codec if TYPE_CHECKING: @@ -52,7 +52,7 @@ from typing_extensions import Self - from zarr.common import JSON + from zarr.core.common import JSON MAX_UINT_64 = 2**64 - 1 ShardMapping = Mapping[ChunkCoords, Buffer] diff --git a/src/zarr/codecs/transpose.py b/src/zarr/codecs/transpose.py index 3f9ae61676..ada45b1b53 100644 --- a/src/zarr/codecs/transpose.py +++ b/src/zarr/codecs/transpose.py @@ -7,10 +7,10 @@ import numpy as np from zarr.abc.codec import ArrayArrayCodec -from zarr.array_spec import ArraySpec -from zarr.buffer import NDBuffer -from zarr.chunk_grids import ChunkGrid -from zarr.common import JSON, ChunkCoordsLike, parse_named_configuration +from zarr.core.array_spec import ArraySpec +from zarr.core.buffer import NDBuffer +from zarr.core.chunk_grids import ChunkGrid +from zarr.core.common import JSON, ChunkCoordsLike, parse_named_configuration from zarr.registry import register_codec if TYPE_CHECKING: diff --git a/src/zarr/codecs/zstd.py b/src/zarr/codecs/zstd.py index 3b3d3f33dd..92a2665425 100644 --- a/src/zarr/codecs/zstd.py +++ b/src/zarr/codecs/zstd.py @@ -8,9 +8,9 @@ from numcodecs.zstd import Zstd from zarr.abc.codec import BytesBytesCodec -from zarr.array_spec import ArraySpec -from zarr.buffer import Buffer, as_numpy_array_wrapper -from zarr.common import JSON, parse_named_configuration, to_thread +from zarr.core.array_spec import ArraySpec +from zarr.core.buffer import Buffer, as_numpy_array_wrapper +from zarr.core.common import JSON, parse_named_configuration, to_thread from zarr.registry import register_codec if TYPE_CHECKING: diff --git a/src/zarr/convenience.py b/src/zarr/convenience.py index be0a6b2813..95269e951d 100644 --- a/src/zarr/convenience.py +++ b/src/zarr/convenience.py @@ -1,35 +1,7 @@ import warnings -from zarr.api.synchronous import ( - consolidate_metadata, - copy, - copy_all, - copy_store, - load, - open, - open_consolidated, - save, - save_array, - save_group, - tree, -) - warnings.warn( "zarr.convenience is deprecated, use zarr.api.synchronous", DeprecationWarning, stacklevel=2, ) - -__all__ = [ - "open", - "save_array", - "save_group", - "save", - "load", - "tree", - "copy_store", - "copy", - "copy_all", - "consolidate_metadata", - "open_consolidated", -] diff --git a/src/zarr/core/array.py b/src/zarr/core/array.py index 84c2f958e3..3738b0859b 100644 --- a/src/zarr/core/array.py +++ b/src/zarr/core/array.py @@ -11,13 +11,17 @@ from zarr.abc.codec import Codec, CodecPipeline from zarr.abc.store import set_or_delete -from zarr.attributes import Attributes -from zarr.buffer import BufferPrototype, NDArrayLike, NDBuffer, default_buffer_prototype -from zarr.chunk_grids import RegularChunkGrid, _guess_chunks -from zarr.chunk_key_encodings import ChunkKeyEncoding, DefaultChunkKeyEncoding, V2ChunkKeyEncoding from zarr.codecs import BytesCodec from zarr.codecs._v2 import V2Compressor, V2Filters -from zarr.common import ( +from zarr.core.attributes import Attributes +from zarr.core.buffer import BufferPrototype, NDArrayLike, NDBuffer, default_buffer_prototype +from zarr.core.chunk_grids import RegularChunkGrid, _guess_chunks +from zarr.core.chunk_key_encodings import ( + ChunkKeyEncoding, + DefaultChunkKeyEncoding, + V2ChunkKeyEncoding, +) +from zarr.core.common import ( JSON, ZARR_JSON, ZARRAY_JSON, @@ -51,11 +55,11 @@ is_scalar, pop_fields, ) +from zarr.core.metadata import ArrayMetadata, ArrayV2Metadata, ArrayV3Metadata from zarr.core.sync import sync -from zarr.metadata import ArrayMetadata, ArrayV2Metadata, ArrayV3Metadata from zarr.registry import get_pipeline_class from zarr.store import StoreLike, StorePath, make_store_path -from zarr.store.core import ( +from zarr.store.common import ( ensure_no_existing_node, ) @@ -2048,6 +2052,3 @@ def info(self) -> None: return sync( self._async_array.info(), ) - - -__all__ = ["Array", "AsyncArray"] diff --git a/src/zarr/array_spec.py b/src/zarr/core/array_spec.py similarity index 80% rename from src/zarr/array_spec.py rename to src/zarr/core/array_spec.py index 0ccdde009e..fd30575c79 100644 --- a/src/zarr/array_spec.py +++ b/src/zarr/core/array_spec.py @@ -1,13 +1,16 @@ from __future__ import annotations from dataclasses import dataclass -from typing import Any, Literal +from typing import Any, Literal, TYPE_CHECKING import numpy as np -from zarr.buffer import BufferPrototype -from zarr.common import ChunkCoords, parse_dtype, parse_fill_value, parse_order, parse_shapelike +from zarr.core.common import parse_dtype, parse_fill_value, parse_order, parse_shapelike + +if TYPE_CHECKING: + from zarr.core.buffer import BufferPrototype + from zarr.core.common import ChunkCoords @dataclass(frozen=True) class ArraySpec: @@ -39,6 +42,3 @@ def __init__( @property def ndim(self) -> int: return len(self.shape) - - -__all__ = ["ArraySpec"] diff --git a/src/zarr/attributes.py b/src/zarr/core/attributes.py similarity index 82% rename from src/zarr/attributes.py rename to src/zarr/core/attributes.py index 4931907b8f..09677f7bdc 100644 --- a/src/zarr/attributes.py +++ b/src/zarr/core/attributes.py @@ -1,13 +1,15 @@ from __future__ import annotations -from collections.abc import Iterator, MutableMapping +from collections.abc import MutableMapping from typing import TYPE_CHECKING -from zarr.common import JSON +from zarr.core.common import JSON if TYPE_CHECKING: - from zarr.array import Array - from zarr.group import Group + from collections.abc import Iterator + + from zarr.core.array import Array + from zarr.core.group import Group class Attributes(MutableMapping[str, JSON]): @@ -33,6 +35,3 @@ def __iter__(self) -> Iterator[str]: def __len__(self) -> int: return len(self._obj.metadata.attributes) - - -__all__ = ["Attributes"] diff --git a/src/zarr/buffer.py b/src/zarr/core/buffer.py similarity index 99% rename from src/zarr/buffer.py rename to src/zarr/core/buffer.py index 9c75ba1410..50252590dd 100644 --- a/src/zarr/buffer.py +++ b/src/zarr/core/buffer.py @@ -15,7 +15,7 @@ import numpy as np import numpy.typing as npt -from zarr.common import ChunkCoords +from zarr.core.common import ChunkCoords from zarr.registry import ( get_buffer_class, get_ndbuffer_class, @@ -27,7 +27,7 @@ from typing_extensions import Self from zarr.codecs.bytes import Endian - from zarr.common import BytesLike + from zarr.core.common import BytesLike @runtime_checkable diff --git a/src/zarr/chunk_grids.py b/src/zarr/core/chunk_grids.py similarity index 99% rename from src/zarr/chunk_grids.py rename to src/zarr/core/chunk_grids.py index 0fbd1d588b..f912872251 100644 --- a/src/zarr/chunk_grids.py +++ b/src/zarr/core/chunk_grids.py @@ -12,7 +12,7 @@ import numpy as np from zarr.abc.metadata import Metadata -from zarr.common import ( +from zarr.core.common import ( JSON, ChunkCoords, ChunkCoordsLike, diff --git a/src/zarr/chunk_key_encodings.py b/src/zarr/core/chunk_key_encodings.py similarity index 98% rename from src/zarr/chunk_key_encodings.py rename to src/zarr/core/chunk_key_encodings.py index 30db8ff5a8..45174bf4af 100644 --- a/src/zarr/chunk_key_encodings.py +++ b/src/zarr/core/chunk_key_encodings.py @@ -5,7 +5,7 @@ from typing import TYPE_CHECKING, Literal, cast from zarr.abc.metadata import Metadata -from zarr.common import ( +from zarr.core.common import ( JSON, ChunkCoords, parse_named_configuration, diff --git a/src/zarr/common.py b/src/zarr/core/common.py similarity index 100% rename from src/zarr/common.py rename to src/zarr/core/common.py diff --git a/src/zarr/core/config.py b/src/zarr/core/config.py index 3f4e91ba9a..67f5c74347 100644 --- a/src/zarr/core/config.py +++ b/src/zarr/core/config.py @@ -60,8 +60,8 @@ def reset(self) -> None: "sharding_indexed": "zarr.codecs.sharding.ShardingCodec", "transpose": "zarr.codecs.transpose.TransposeCodec", }, - "buffer": "zarr.buffer.Buffer", - "ndbuffer": "zarr.buffer.NDBuffer", + "buffer": "zarr.core.buffer.Buffer", + "ndbuffer": "zarr.core.buffer.NDBuffer", } ], ) @@ -72,7 +72,3 @@ def parse_indexing_order(data: Any) -> Literal["C", "F"]: return cast(Literal["C", "F"], data) msg = f"Expected one of ('C', 'F'), got {data} instead." raise ValueError(msg) - - -# TODO: why is parse_indexing_order here? -__all__ = ["config", "parse_indexing_order"] diff --git a/src/zarr/core/group.py b/src/zarr/core/group.py index 3432858847..86d27e3a97 100644 --- a/src/zarr/core/group.py +++ b/src/zarr/core/group.py @@ -13,10 +13,11 @@ from zarr.abc.codec import Codec from zarr.abc.metadata import Metadata from zarr.abc.store import set_or_delete -from zarr.attributes import Attributes -from zarr.buffer import Buffer, BufferPrototype, default_buffer_prototype -from zarr.chunk_key_encodings import ChunkKeyEncoding -from zarr.common import ( +from zarr.core.array import Array, AsyncArray +from zarr.core.attributes import Attributes +from zarr.core.buffer import default_buffer_prototype +from zarr.core.chunk_key_encodings import ChunkKeyEncoding +from zarr.core.common import ( JSON, ZARR_JSON, ZARRAY_JSON, @@ -25,16 +26,17 @@ ChunkCoords, ZarrFormat, ) -from zarr.core.array import Array, AsyncArray from zarr.core.config import config from zarr.core.sync import SyncMixin, sync from zarr.store import StoreLike, StorePath, make_store_path -from zarr.store.core import ensure_no_existing_node +from zarr.store.common import ensure_no_existing_node if TYPE_CHECKING: from collections.abc import AsyncGenerator, Iterable from typing import Any + from zarr.core.buffer import Buffer, BufferPrototype + logger = logging.getLogger("zarr.group") diff --git a/src/zarr/core/indexing.py b/src/zarr/core/indexing.py index 6987f69c11..153483330c 100644 --- a/src/zarr/core/indexing.py +++ b/src/zarr/core/indexing.py @@ -23,12 +23,13 @@ import numpy as np import numpy.typing as npt -from zarr.buffer import NDArrayLike -from zarr.common import ChunkCoords, product +from zarr.core.buffer import NDArrayLike +from zarr.core.common import product if TYPE_CHECKING: - from zarr.array import Array - from zarr.chunk_grids import ChunkGrid + from zarr.core.array import Array + from zarr.core.chunk_grids import ChunkGrid + from zarr.core.common import ChunkCoords IntSequence = list[int] | npt.NDArray[np.intp] ArrayOfIntOrBool = npt.NDArray[np.intp] | npt.NDArray[np.bool_] @@ -197,7 +198,7 @@ def is_pure_orthogonal_indexing(selection: Selection, ndim: int) -> TypeGuard[Or def get_chunk_shape(chunk_grid: ChunkGrid) -> ChunkCoords: - from zarr.chunk_grids import RegularChunkGrid + from zarr.core.chunk_grids import RegularChunkGrid assert isinstance( chunk_grid, RegularChunkGrid diff --git a/src/zarr/metadata.py b/src/zarr/core/metadata.py similarity index 98% rename from src/zarr/metadata.py rename to src/zarr/core/metadata.py index cc40e8dc62..d541e43205 100644 --- a/src/zarr/metadata.py +++ b/src/zarr/core/metadata.py @@ -12,9 +12,9 @@ from zarr.abc.codec import ArrayArrayCodec, ArrayBytesCodec, BytesBytesCodec, Codec, CodecPipeline from zarr.abc.metadata import Metadata -from zarr.buffer import Buffer, BufferPrototype, default_buffer_prototype -from zarr.chunk_grids import ChunkGrid, RegularChunkGrid -from zarr.chunk_key_encodings import ChunkKeyEncoding, parse_separator +from zarr.core.buffer import Buffer, BufferPrototype, default_buffer_prototype +from zarr.core.chunk_grids import ChunkGrid, RegularChunkGrid +from zarr.core.chunk_key_encodings import ChunkKeyEncoding, parse_separator from zarr.registry import get_codec_class, get_pipeline_class if TYPE_CHECKING: @@ -22,8 +22,8 @@ import numcodecs.abc -from zarr.array_spec import ArraySpec -from zarr.common import ( +from zarr.core.array_spec import ArraySpec +from zarr.core.common import ( JSON, ZARR_JSON, ZARRAY_JSON, diff --git a/src/zarr/core/sync.py b/src/zarr/core/sync.py index 3467e1f149..ff7f9a43af 100644 --- a/src/zarr/core/sync.py +++ b/src/zarr/core/sync.py @@ -1,19 +1,18 @@ from __future__ import annotations -from typing import TYPE_CHECKING, TypeVar - -if TYPE_CHECKING: - from collections.abc import AsyncIterator, Coroutine - from typing import Any - import asyncio import threading from concurrent.futures import wait +from typing import TYPE_CHECKING, TypeVar from typing_extensions import ParamSpec from zarr.core.config import config +if TYPE_CHECKING: + from collections.abc import AsyncIterator, Coroutine + from typing import Any + P = ParamSpec("P") T = TypeVar("T") @@ -128,6 +127,3 @@ async def iter_to_list() -> list[T]: return [item async for item in async_iterator] return self._sync(iter_to_list()) - - -__all__ = ["sync", "SyncMixin"] diff --git a/src/zarr/creation.py b/src/zarr/creation.py index df3f764610..91de696a6b 100644 --- a/src/zarr/creation.py +++ b/src/zarr/creation.py @@ -1,37 +1,7 @@ import warnings -from zarr.api.synchronous import ( - array, - create, - empty, - empty_like, - full, - full_like, - ones, - ones_like, - open_array, - open_like, - zeros, - zeros_like, -) - warnings.warn( "zarr.creation is deprecated, use zarr.api.synchronous", DeprecationWarning, stacklevel=2, ) - -__all__ = [ - "create", - "empty", - "zeros", - "ones", - "full", - "array", - "open_array", - "empty_like", - "zeros_like", - "ones_like", - "full_like", - "open_like", -] diff --git a/src/zarr/registry.py b/src/zarr/registry.py index 095d24b51d..b774c620da 100644 --- a/src/zarr/registry.py +++ b/src/zarr/registry.py @@ -2,16 +2,16 @@ import warnings from collections import defaultdict +from importlib.metadata import entry_points as get_entry_points from typing import TYPE_CHECKING, Any, Generic, TypeVar -if TYPE_CHECKING: - from zarr.abc.codec import Codec, CodecPipeline - from zarr.buffer import Buffer, NDBuffer +from zarr.core.config import BadConfigError, config -from importlib.metadata import EntryPoint -from importlib.metadata import entry_points as get_entry_points +if TYPE_CHECKING: + from importlib.metadata import EntryPoint -from zarr.core.config import BadConfigError, config + from zarr.abc.codec import Codec, CodecPipeline + from zarr.core.buffer import Buffer, NDBuffer T = TypeVar("T") @@ -178,3 +178,16 @@ def get_ndbuffer_class(reload_config: bool = False) -> type[NDBuffer]: _collect_entrypoints() + + +__all__ = [ + "Registry", + "register_codec", + "register_pipeline", + "register_buffer", + "register_ndbuffer", + "get_codec_class", + "get_pipeline_class", + "get_buffer_class", + "get_ndbuffer_class", +] diff --git a/src/zarr/store/__init__.py b/src/zarr/store/__init__.py index fbdcdb9255..bc5a0efab2 100644 --- a/src/zarr/store/__init__.py +++ b/src/zarr/store/__init__.py @@ -1,6 +1,6 @@ -from zarr.store.core import StoreLike, StorePath, make_store_path -from zarr.store.local import LocalStore -from zarr.store.memory import MemoryStore -from zarr.store.remote import RemoteStore +from zarr.store._local import LocalStore +from zarr.store._memory import MemoryStore +from zarr.store._remote import RemoteStore +from zarr.store.common import StoreLike, StorePath, make_store_path __all__ = ["StorePath", "StoreLike", "make_store_path", "RemoteStore", "LocalStore", "MemoryStore"] diff --git a/src/zarr/store/local.py b/src/zarr/store/_local.py similarity index 96% rename from src/zarr/store/local.py rename to src/zarr/store/_local.py index 3cc42c6c0e..97a17b0620 100644 --- a/src/zarr/store/local.py +++ b/src/zarr/store/_local.py @@ -5,10 +5,15 @@ import shutil from collections.abc import AsyncGenerator from pathlib import Path +from typing import TYPE_CHECKING from zarr.abc.store import Store -from zarr.buffer import Buffer, BufferPrototype -from zarr.common import AccessModeLiteral, concurrent_map, to_thread +from zarr.core.common import concurrent_map, to_thread +from zarr.core.buffer import Buffer + +if TYPE_CHECKING: + from zarr.core.buffer import BufferPrototype + from zarr.core.common import AccessModeLiteral def _get( diff --git a/src/zarr/store/memory.py b/src/zarr/store/_memory.py similarity index 92% rename from src/zarr/store/memory.py rename to src/zarr/store/_memory.py index dd3e52e703..999d750755 100644 --- a/src/zarr/store/memory.py +++ b/src/zarr/store/_memory.py @@ -1,11 +1,16 @@ from __future__ import annotations from collections.abc import AsyncGenerator, MutableMapping +from typing import TYPE_CHECKING from zarr.abc.store import Store -from zarr.buffer import Buffer, BufferPrototype -from zarr.common import AccessModeLiteral, concurrent_map -from zarr.store.utils import _normalize_interval_index +from zarr.core.buffer import Buffer +from zarr.core.common import concurrent_map +from zarr.store._utils import _normalize_interval_index + +if TYPE_CHECKING: + from zarr.core.buffer import BufferPrototype + from zarr.core.common import AccessModeLiteral # TODO: this store could easily be extended to wrap any MutableMapping store from v2 diff --git a/src/zarr/store/remote.py b/src/zarr/store/_remote.py similarity index 97% rename from src/zarr/store/remote.py rename to src/zarr/store/_remote.py index 84f01c7852..186b2298bf 100644 --- a/src/zarr/store/remote.py +++ b/src/zarr/store/_remote.py @@ -6,16 +6,15 @@ import fsspec from zarr.abc.store import Store -from zarr.buffer import BufferPrototype -from zarr.common import AccessModeLiteral -from zarr.store.core import _dereference_path +from zarr.store.common import _dereference_path +from zarr.core.buffer import Buffer if TYPE_CHECKING: from fsspec.asyn import AsyncFileSystem from upath import UPath - from zarr.buffer import Buffer, BufferPrototype - from zarr.common import BytesLike + from zarr.core.buffer import BufferPrototype + from zarr.core.common import AccessModeLiteral, BytesLike class RemoteStore(Store): diff --git a/src/zarr/store/utils.py b/src/zarr/store/_utils.py similarity index 94% rename from src/zarr/store/utils.py rename to src/zarr/store/_utils.py index 17c9234221..04a06351c5 100644 --- a/src/zarr/store/utils.py +++ b/src/zarr/store/_utils.py @@ -1,4 +1,4 @@ -from zarr.buffer import Buffer +from zarr.core.buffer import Buffer def _normalize_interval_index( diff --git a/src/zarr/store/core.py b/src/zarr/store/common.py similarity index 95% rename from src/zarr/store/core.py rename to src/zarr/store/common.py index 4d31118a54..984f28f699 100644 --- a/src/zarr/store/core.py +++ b/src/zarr/store/common.py @@ -2,14 +2,18 @@ import json from pathlib import Path -from typing import Any, Literal +from typing import Any, Literal, TYPE_CHECKING from zarr.abc.store import AccessMode, Store -from zarr.buffer import Buffer, BufferPrototype, default_buffer_prototype -from zarr.common import ZARR_JSON, ZARRAY_JSON, ZGROUP_JSON, AccessModeLiteral, ZarrFormat +from zarr.core.buffer import Buffer, default_buffer_prototype +from zarr.core.common import ZARR_JSON, ZARRAY_JSON, ZGROUP_JSON, ZarrFormat from zarr.errors import ContainsArrayAndGroupError, ContainsArrayError, ContainsGroupError -from zarr.store.local import LocalStore -from zarr.store.memory import MemoryStore +from zarr.store._local import LocalStore +from zarr.store._memory import MemoryStore + +if TYPE_CHECKING: + from zarr.core.buffer import BufferPrototype + from zarr.core.common import AccessModeLiteral def _dereference_path(root: str, path: str) -> str: diff --git a/src/zarr/testing/__init__.py b/src/zarr/testing/__init__.py index 35b91f9167..0b4d8cf417 100644 --- a/src/zarr/testing/__init__.py +++ b/src/zarr/testing/__init__.py @@ -6,4 +6,8 @@ else: warnings.warn("pytest not installed, skipping test suite", stacklevel=2) -__all__ = ["StoreTests"] +from zarr.testing.utils import assert_bytes_equal + +# TODO: import public buffer tests? + +__all__ = ["StoreTests", "assert_bytes_equal"] diff --git a/src/zarr/testing/buffer.py b/src/zarr/testing/buffer.py index d2da1c5a6e..244736c925 100644 --- a/src/zarr/testing/buffer.py +++ b/src/zarr/testing/buffer.py @@ -7,7 +7,7 @@ import numpy as np import numpy.typing as npt -from zarr.buffer import Buffer, BufferPrototype, NDBuffer +from zarr.core.buffer import Buffer, BufferPrototype, NDBuffer from zarr.store import MemoryStore if TYPE_CHECKING: @@ -64,3 +64,10 @@ async def get( if ret is not None: assert isinstance(ret, prototype.buffer) return ret + + +__all__ = [ + "TestBuffer", + "NDBufferUsingTestNDArrayLike", + "StoreExpectingTestBuffer", +] diff --git a/src/zarr/testing/store.py b/src/zarr/testing/store.py index 4fdf497a68..e739aa9a40 100644 --- a/src/zarr/testing/store.py +++ b/src/zarr/testing/store.py @@ -3,8 +3,8 @@ import pytest from zarr.abc.store import AccessMode, Store -from zarr.buffer import Buffer, default_buffer_prototype -from zarr.store.utils import _normalize_interval_index +from zarr.core.buffer import Buffer, default_buffer_prototype +from zarr.store._utils import _normalize_interval_index from zarr.testing.utils import assert_bytes_equal S = TypeVar("S", bound=Store) @@ -199,3 +199,6 @@ async def test_list_dir(self, store: S) -> None: keys_observed = [k async for k in store.list_dir("foo/")] assert len(keys_expected) == len(keys_observed), keys_observed assert set(keys_observed) == set(keys_expected), keys_observed + + +__all__ = ["StoreTests"] diff --git a/src/zarr/testing/utils.py b/src/zarr/testing/utils.py index 67c6c72de7..73d035b6cd 100644 --- a/src/zarr/testing/utils.py +++ b/src/zarr/testing/utils.py @@ -1,7 +1,7 @@ from __future__ import annotations -from zarr.buffer import Buffer -from zarr.common import BytesLike +from zarr.core.buffer import Buffer +from zarr.core.common import BytesLike def assert_bytes_equal(b1: Buffer | BytesLike | None, b2: Buffer | BytesLike | None) -> None: @@ -16,3 +16,6 @@ def assert_bytes_equal(b1: Buffer | BytesLike | None, b2: Buffer | BytesLike | N if isinstance(b2, Buffer): b2 = b2.to_bytes() assert b1 == b2 + + +__all__ = ["assert_bytes_equal"] diff --git a/tests/v3/conftest.py b/tests/v3/conftest.py index 74d50a071d..acdd050fff 100644 --- a/tests/v3/conftest.py +++ b/tests/v3/conftest.py @@ -8,7 +8,7 @@ from zarr import AsyncGroup, config from zarr.abc.store import Store -from zarr.common import ChunkCoords, MemoryOrder, ZarrFormat +from zarr.core.common import ChunkCoords, MemoryOrder, ZarrFormat if TYPE_CHECKING: from typing import Any, Literal @@ -20,7 +20,7 @@ from hypothesis import HealthCheck, Verbosity, settings from zarr.store import LocalStore, MemoryStore, StorePath -from zarr.store.remote import RemoteStore +from zarr.store._remote import RemoteStore async def parse_store( diff --git a/tests/v3/package_with_entrypoint/__init__.py b/tests/v3/package_with_entrypoint/__init__.py index 4d626808d8..0e84cde0d5 100644 --- a/tests/v3/package_with_entrypoint/__init__.py +++ b/tests/v3/package_with_entrypoint/__init__.py @@ -3,10 +3,10 @@ from numpy import ndarray from zarr.abc.codec import ArrayBytesCodec, CodecInput, CodecPipeline -from zarr.array_spec import ArraySpec -from zarr.buffer import Buffer, NDBuffer from zarr.codecs import BytesCodec -from zarr.common import BytesLike +from zarr.core.array_spec import ArraySpec +from zarr.core.buffer import Buffer, NDBuffer +from zarr.core.common import BytesLike class TestEntrypointCodec(ArrayBytesCodec): diff --git a/tests/v3/test_array.py b/tests/v3/test_array.py index 64305c256b..fb726757dc 100644 --- a/tests/v3/test_array.py +++ b/tests/v3/test_array.py @@ -4,10 +4,10 @@ import pytest from zarr import Array, Group -from zarr.common import ZarrFormat +from zarr.core.common import ZarrFormat from zarr.errors import ContainsArrayError, ContainsGroupError from zarr.store import LocalStore, MemoryStore -from zarr.store.core import StorePath +from zarr.store.common import StorePath @pytest.mark.parametrize("store", ("local", "memory"), indirect=["store"]) diff --git a/tests/v3/test_buffer.py b/tests/v3/test_buffer.py index 8fbbfb8038..298a7f7eed 100644 --- a/tests/v3/test_buffer.py +++ b/tests/v3/test_buffer.py @@ -4,14 +4,14 @@ import pytest from zarr import AsyncArray -from zarr.buffer import ArrayLike, BufferPrototype, NDArrayLike, numpy_buffer_prototype from zarr.codecs.blosc import BloscCodec from zarr.codecs.bytes import BytesCodec from zarr.codecs.crc32c_ import Crc32cCodec from zarr.codecs.gzip import GzipCodec from zarr.codecs.transpose import TransposeCodec from zarr.codecs.zstd import ZstdCodec -from zarr.store.core import StorePath +from zarr.core.buffer import ArrayLike, BufferPrototype, NDArrayLike, numpy_buffer_prototype +from zarr.store.common import StorePath from zarr.testing.buffer import ( NDBufferUsingTestNDArrayLike, StoreExpectingTestBuffer, diff --git a/tests/v3/test_chunk_grids.py b/tests/v3/test_chunk_grids.py index 3cc6b64e57..e1b4df10a7 100644 --- a/tests/v3/test_chunk_grids.py +++ b/tests/v3/test_chunk_grids.py @@ -1,7 +1,7 @@ import numpy as np import pytest -from zarr.chunk_grids import _guess_chunks +from zarr.core.chunk_grids import _guess_chunks @pytest.mark.parametrize( diff --git a/tests/v3/test_codecs/test_blosc.py b/tests/v3/test_codecs/test_blosc.py index 814db11a57..5de4c9fa99 100644 --- a/tests/v3/test_codecs/test_blosc.py +++ b/tests/v3/test_codecs/test_blosc.py @@ -5,9 +5,9 @@ from zarr import AsyncArray from zarr.abc.store import Store -from zarr.buffer import default_buffer_prototype from zarr.codecs import BloscCodec, BytesCodec, ShardingCodec -from zarr.store.core import StorePath +from zarr.core.buffer import default_buffer_prototype +from zarr.store.common import StorePath @pytest.mark.parametrize("store", ("local", "memory"), indirect=["store"]) diff --git a/tests/v3/test_codecs/test_codecs.py b/tests/v3/test_codecs/test_codecs.py index 0730c5bedb..7e717e5b50 100644 --- a/tests/v3/test_codecs/test_codecs.py +++ b/tests/v3/test_codecs/test_codecs.py @@ -10,14 +10,14 @@ from zarr import Array, AsyncArray, config from zarr.abc.codec import Codec from zarr.abc.store import Store -from zarr.buffer import default_buffer_prototype from zarr.codecs import ( BytesCodec, GzipCodec, ShardingCodec, TransposeCodec, ) -from zarr.common import MemoryOrder +from zarr.core.buffer import default_buffer_prototype +from zarr.core.common import MemoryOrder from zarr.core.indexing import Selection, morton_order_iter from zarr.store import StorePath from zarr.testing.utils import assert_bytes_equal diff --git a/tests/v3/test_codecs/test_endian.py b/tests/v3/test_codecs/test_endian.py index a9ebbf700f..f97d95d9b7 100644 --- a/tests/v3/test_codecs/test_endian.py +++ b/tests/v3/test_codecs/test_endian.py @@ -6,9 +6,9 @@ import zarr.v2 from zarr import AsyncArray from zarr.abc.store import Store -from zarr.buffer import default_buffer_prototype from zarr.codecs import BytesCodec -from zarr.store.core import StorePath +from zarr.core.buffer import default_buffer_prototype +from zarr.store.common import StorePath from zarr.testing.utils import assert_bytes_equal from .test_codecs import _AsyncArrayProxy diff --git a/tests/v3/test_codecs/test_gzip.py b/tests/v3/test_codecs/test_gzip.py index 3d33d885fc..6495f8236c 100644 --- a/tests/v3/test_codecs/test_gzip.py +++ b/tests/v3/test_codecs/test_gzip.py @@ -4,7 +4,7 @@ from zarr import Array from zarr.abc.store import Store from zarr.codecs import BytesCodec, GzipCodec -from zarr.store.core import StorePath +from zarr.store.common import StorePath @pytest.mark.parametrize("store", ("local", "memory"), indirect=["store"]) diff --git a/tests/v3/test_codecs/test_sharding.py b/tests/v3/test_codecs/test_sharding.py index ed338f0ec1..e5f66224e9 100644 --- a/tests/v3/test_codecs/test_sharding.py +++ b/tests/v3/test_codecs/test_sharding.py @@ -5,7 +5,6 @@ from zarr import Array, AsyncArray from zarr.abc.store import Store -from zarr.buffer import default_buffer_prototype from zarr.codecs import ( BloscCodec, BytesCodec, @@ -13,7 +12,8 @@ ShardingCodecIndexLocation, TransposeCodec, ) -from zarr.store.core import StorePath +from zarr.core.buffer import default_buffer_prototype +from zarr.store.common import StorePath from ..conftest import ArrayRequest from .test_codecs import _AsyncArrayProxy, order_from_dim diff --git a/tests/v3/test_codecs/test_transpose.py b/tests/v3/test_codecs/test_transpose.py index b3cedd2b68..b9aa6cc4b6 100644 --- a/tests/v3/test_codecs/test_transpose.py +++ b/tests/v3/test_codecs/test_transpose.py @@ -5,10 +5,10 @@ from zarr import Array, AsyncArray, config from zarr.abc.codec import Codec from zarr.abc.store import Store -from zarr.buffer import default_buffer_prototype from zarr.codecs import BytesCodec, ShardingCodec, TransposeCodec -from zarr.common import MemoryOrder -from zarr.store.core import StorePath +from zarr.core.buffer import default_buffer_prototype +from zarr.core.common import MemoryOrder +from zarr.store.common import StorePath from .test_codecs import _AsyncArrayProxy diff --git a/tests/v3/test_codecs/test_zstd.py b/tests/v3/test_codecs/test_zstd.py index 8b8b71842d..0726e5944c 100644 --- a/tests/v3/test_codecs/test_zstd.py +++ b/tests/v3/test_codecs/test_zstd.py @@ -4,7 +4,7 @@ from zarr import Array from zarr.abc.store import Store from zarr.codecs import BytesCodec, ZstdCodec -from zarr.store.core import StorePath +from zarr.store.common import StorePath @pytest.mark.parametrize("store", ("local", "memory"), indirect=["store"]) diff --git a/tests/v3/test_common.py b/tests/v3/test_common.py index 7f731cde52..f919b4d5f7 100644 --- a/tests/v3/test_common.py +++ b/tests/v3/test_common.py @@ -9,7 +9,7 @@ import numpy as np import pytest -from zarr.common import parse_name, parse_shapelike, product +from zarr.core.common import parse_name, parse_shapelike, product from zarr.core.config import parse_indexing_order diff --git a/tests/v3/test_config.py b/tests/v3/test_config.py index 6d9713366f..881833797c 100644 --- a/tests/v3/test_config.py +++ b/tests/v3/test_config.py @@ -11,9 +11,9 @@ from zarr import Array, zeros from zarr.abc.codec import CodecInput, CodecOutput, CodecPipeline from zarr.abc.store import ByteSetter -from zarr.array_spec import ArraySpec -from zarr.buffer import NDBuffer from zarr.codecs import BatchedCodecPipeline, BloscCodec, BytesCodec, Crc32cCodec, ShardingCodec +from zarr.core.array_spec import ArraySpec +from zarr.core.buffer import NDBuffer from zarr.core.config import BadConfigError, config from zarr.core.indexing import SelectorTuple from zarr.registry import ( @@ -46,8 +46,8 @@ def test_config_defaults_set() -> None: "path": "zarr.codecs.pipeline.BatchedCodecPipeline", "batch_size": 1, }, - "buffer": "zarr.buffer.Buffer", - "ndbuffer": "zarr.buffer.NDBuffer", + "buffer": "zarr.core.buffer.Buffer", + "ndbuffer": "zarr.core.buffer.NDBuffer", "codecs": { "blosc": "zarr.codecs.blosc.BloscCodec", "gzip": "zarr.codecs.gzip.GzipCodec", diff --git a/tests/v3/test_group.py b/tests/v3/test_group.py index 6191ddf7f6..39921c26d8 100644 --- a/tests/v3/test_group.py +++ b/tests/v3/test_group.py @@ -7,13 +7,13 @@ from _pytest.compat import LEGACY_PATH from zarr import Array, AsyncArray, AsyncGroup, Group -from zarr.buffer import Buffer -from zarr.common import ZarrFormat +from zarr.core.buffer import Buffer +from zarr.core.common import ZarrFormat from zarr.core.group import GroupMetadata from zarr.core.sync import sync from zarr.errors import ContainsArrayError, ContainsGroupError from zarr.store import LocalStore, MemoryStore, StorePath -from zarr.store.core import make_store_path +from zarr.store.common import make_store_path from .conftest import parse_store diff --git a/tests/v3/test_indexing.py b/tests/v3/test_indexing.py index 982dfc5037..45353b1f5e 100644 --- a/tests/v3/test_indexing.py +++ b/tests/v3/test_indexing.py @@ -12,8 +12,8 @@ import zarr from zarr.abc.store import Store -from zarr.buffer import BufferPrototype, NDBuffer -from zarr.common import ChunkCoords +from zarr.core.buffer import BufferPrototype, NDBuffer +from zarr.core.common import ChunkCoords from zarr.core.indexing import ( make_slice_selection, normalize_integer_selection, @@ -22,8 +22,8 @@ replace_ellipsis, ) from zarr.registry import get_ndbuffer_class -from zarr.store.core import StorePath -from zarr.store.memory import MemoryStore +from zarr.store._memory import MemoryStore +from zarr.store.common import StorePath @pytest.fixture diff --git a/tests/v3/test_metadata/test_v2.py b/tests/v3/test_metadata/test_v2.py index 2d6f4d0cf5..54f26d91ca 100644 --- a/tests/v3/test_metadata/test_v2.py +++ b/tests/v3/test_metadata/test_v2.py @@ -10,7 +10,7 @@ import pytest from zarr.codecs import GzipCodec -from zarr.metadata import ArrayV2Metadata, parse_zarr_format_v2 +from zarr.core.metadata import ArrayV2Metadata, parse_zarr_format_v2 def test_parse_zarr_format_valid() -> None: diff --git a/tests/v3/test_metadata/test_v3.py b/tests/v3/test_metadata/test_v3.py index 2b25c776e0..eedcdf6234 100644 --- a/tests/v3/test_metadata/test_v3.py +++ b/tests/v3/test_metadata/test_v3.py @@ -4,8 +4,8 @@ from typing import TYPE_CHECKING, Literal from zarr.abc.codec import Codec -from zarr.chunk_key_encodings import DefaultChunkKeyEncoding, V2ChunkKeyEncoding from zarr.codecs.bytes import BytesCodec +from zarr.core.chunk_key_encodings import DefaultChunkKeyEncoding, V2ChunkKeyEncoding if TYPE_CHECKING: from typing import Any @@ -15,9 +15,9 @@ import numpy as np import pytest -from zarr.metadata import ArrayV3Metadata, parse_dimension_names -from zarr.metadata import parse_fill_value_v3 as parse_fill_value -from zarr.metadata import parse_zarr_format_v3 as parse_zarr_format +from zarr.core.metadata import ArrayV3Metadata, parse_dimension_names +from zarr.core.metadata import parse_fill_value_v3 as parse_fill_value +from zarr.core.metadata import parse_zarr_format_v3 as parse_zarr_format bool_dtypes = ("bool",) diff --git a/tests/v3/test_store/test_core.py b/tests/v3/test_store/test_core.py index 1d277cf502..2142a5ebcd 100644 --- a/tests/v3/test_store/test_core.py +++ b/tests/v3/test_store/test_core.py @@ -2,9 +2,9 @@ import pytest -from zarr.store.core import make_store_path -from zarr.store.local import LocalStore -from zarr.store.memory import MemoryStore +from zarr.store._local import LocalStore +from zarr.store._memory import MemoryStore +from zarr.store.common import make_store_path async def test_make_store_path(tmpdir) -> None: diff --git a/tests/v3/test_store/test_local.py b/tests/v3/test_store/test_local.py index 6b7f91b87d..fc57d4db9f 100644 --- a/tests/v3/test_store/test_local.py +++ b/tests/v3/test_store/test_local.py @@ -2,8 +2,8 @@ import pytest -from zarr.buffer import Buffer -from zarr.store.local import LocalStore +from zarr.core.buffer import Buffer +from zarr.store._local import LocalStore from zarr.testing.store import StoreTests diff --git a/tests/v3/test_store/test_memory.py b/tests/v3/test_store/test_memory.py index 5b8f1ef875..f71c971114 100644 --- a/tests/v3/test_store/test_memory.py +++ b/tests/v3/test_store/test_memory.py @@ -2,8 +2,8 @@ import pytest -from zarr.buffer import Buffer -from zarr.store.memory import MemoryStore +from zarr.core.buffer import Buffer +from zarr.store._memory import MemoryStore from zarr.testing.store import StoreTests diff --git a/tests/v3/test_store/test_remote.py b/tests/v3/test_store/test_remote.py index 0ce89ab503..2eec9d29cf 100644 --- a/tests/v3/test_store/test_remote.py +++ b/tests/v3/test_store/test_remote.py @@ -4,7 +4,7 @@ import pytest from upath import UPath -from zarr.buffer import Buffer, default_buffer_prototype +from zarr.core.buffer import Buffer, default_buffer_prototype from zarr.core.sync import sync from zarr.store import RemoteStore from zarr.testing.store import StoreTests From 99e20b343d34a640cedf580d70bdf21d3daa4655 Mon Sep 17 00:00:00 2001 From: Joseph Hamman Date: Mon, 12 Aug 2024 13:59:09 -0700 Subject: [PATCH 3/5] lint --- src/zarr/core/array_spec.py | 4 ++-- src/zarr/store/_local.py | 2 +- src/zarr/store/_remote.py | 2 +- src/zarr/store/common.py | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/zarr/core/array_spec.py b/src/zarr/core/array_spec.py index fd30575c79..d2f46057e4 100644 --- a/src/zarr/core/array_spec.py +++ b/src/zarr/core/array_spec.py @@ -1,17 +1,17 @@ from __future__ import annotations from dataclasses import dataclass -from typing import Any, Literal, TYPE_CHECKING +from typing import TYPE_CHECKING, Any, Literal import numpy as np - from zarr.core.common import parse_dtype, parse_fill_value, parse_order, parse_shapelike if TYPE_CHECKING: from zarr.core.buffer import BufferPrototype from zarr.core.common import ChunkCoords + @dataclass(frozen=True) class ArraySpec: shape: ChunkCoords diff --git a/src/zarr/store/_local.py b/src/zarr/store/_local.py index 97a17b0620..6510305844 100644 --- a/src/zarr/store/_local.py +++ b/src/zarr/store/_local.py @@ -8,8 +8,8 @@ from typing import TYPE_CHECKING from zarr.abc.store import Store -from zarr.core.common import concurrent_map, to_thread from zarr.core.buffer import Buffer +from zarr.core.common import concurrent_map, to_thread if TYPE_CHECKING: from zarr.core.buffer import BufferPrototype diff --git a/src/zarr/store/_remote.py b/src/zarr/store/_remote.py index 186b2298bf..f5ea694b0a 100644 --- a/src/zarr/store/_remote.py +++ b/src/zarr/store/_remote.py @@ -6,8 +6,8 @@ import fsspec from zarr.abc.store import Store -from zarr.store.common import _dereference_path from zarr.core.buffer import Buffer +from zarr.store.common import _dereference_path if TYPE_CHECKING: from fsspec.asyn import AsyncFileSystem diff --git a/src/zarr/store/common.py b/src/zarr/store/common.py index 984f28f699..30ae3812cf 100644 --- a/src/zarr/store/common.py +++ b/src/zarr/store/common.py @@ -2,7 +2,7 @@ import json from pathlib import Path -from typing import Any, Literal, TYPE_CHECKING +from typing import TYPE_CHECKING, Any, Literal from zarr.abc.store import AccessMode, Store from zarr.core.buffer import Buffer, default_buffer_prototype From 4725370095554edde9948c5e5b88ca5452c64977 Mon Sep 17 00:00:00 2001 From: Joseph Hamman Date: Mon, 12 Aug 2024 14:14:41 -0700 Subject: [PATCH 4/5] rev 3 --- src/zarr/abc/codec.py | 23 +++++----- src/zarr/abc/metadata.py | 5 +-- src/zarr/abc/store.py | 5 +-- src/zarr/api/asynchronous.py | 57 ++++++++++++------------ src/zarr/api/synchronous.py | 56 +++++++++++------------ src/zarr/convenience.py | 28 ++++++++++++ src/zarr/creation.py | 30 +++++++++++++ src/zarr/store/__init__.py | 6 +-- src/zarr/store/common.py | 4 +- src/zarr/store/{_local.py => local.py} | 0 src/zarr/store/{_memory.py => memory.py} | 0 src/zarr/store/{_remote.py => remote.py} | 0 tests/v3/conftest.py | 2 +- tests/v3/test_indexing.py | 2 +- tests/v3/test_store/test_core.py | 4 +- tests/v3/test_store/test_local.py | 2 +- tests/v3/test_store/test_memory.py | 2 +- 17 files changed, 140 insertions(+), 86 deletions(-) rename src/zarr/store/{_local.py => local.py} (100%) rename src/zarr/store/{_memory.py => memory.py} (100%) rename src/zarr/store/{_remote.py => remote.py} (100%) diff --git a/src/zarr/abc/codec.py b/src/zarr/abc/codec.py index e15c278bca..fa76399f90 100644 --- a/src/zarr/abc/codec.py +++ b/src/zarr/abc/codec.py @@ -20,6 +20,17 @@ from zarr.core.common import JSON from zarr.core.indexing import SelectorTuple +__all__ = [ + "CodecInput", + "CodecOutput", + "ArrayArrayCodec", + "ArrayBytesCodec", + "BytesBytesCodec", + "ArrayBytesCodecPartialDecodeMixin", + "ArrayBytesCodecPartialEncodeMixin", + "CodecPipeline", +] + CodecInput = TypeVar("CodecInput", bound=NDBuffer | Buffer) CodecOutput = TypeVar("CodecOutput", bound=NDBuffer | Buffer) @@ -421,15 +432,3 @@ async def wrap(chunk: CodecInput | None, chunk_spec: ArraySpec) -> CodecOutput | return await func(chunk, chunk_spec) return wrap - - -__all__ = [ - "CodecInput", - "CodecOutput", - "ArrayArrayCodec", - "ArrayBytesCodec", - "BytesBytesCodec", - "ArrayBytesCodecPartialDecodeMixin", - "ArrayBytesCodecPartialEncodeMixin", - "CodecPipeline", -] diff --git a/src/zarr/abc/metadata.py b/src/zarr/abc/metadata.py index 9cdadddb9e..0ddf762766 100644 --- a/src/zarr/abc/metadata.py +++ b/src/zarr/abc/metadata.py @@ -10,6 +10,8 @@ from zarr.core.common import JSON +__all__ = ["Metadata"] + @dataclass(frozen=True) class Metadata: @@ -44,6 +46,3 @@ def from_dict(cls, data: dict[str, JSON]) -> Self: ... return cls(**data) - - -__all__ = ["Metadata"] diff --git a/src/zarr/abc/store.py b/src/zarr/abc/store.py index ae9b25cb7d..00b81a3aad 100644 --- a/src/zarr/abc/store.py +++ b/src/zarr/abc/store.py @@ -7,6 +7,8 @@ from zarr.core.buffer import Buffer, BufferPrototype from zarr.core.common import AccessModeLiteral, BytesLike +__all__ = ["Store", "AccessMode", "ByteGetter", "ByteSetter", "set_or_delete"] + class AccessMode(NamedTuple): readonly: bool @@ -245,6 +247,3 @@ async def set_or_delete(byte_setter: ByteSetter, value: Buffer | None) -> None: await byte_setter.delete() else: await byte_setter.set(value) - - -__all__ = ["Store", "AccessMode", "ByteGetter", "ByteSetter", "set_or_delete"] diff --git a/src/zarr/api/asynchronous.py b/src/zarr/api/asynchronous.py index d47d30ca1c..ad89584b44 100644 --- a/src/zarr/api/asynchronous.py +++ b/src/zarr/api/asynchronous.py @@ -20,6 +20,34 @@ make_store_path, ) +__all__ = [ + "consolidate_metadata", + "copy", + "copy_all", + "copy_store", + "load", + "open", + "open_consolidated", + "save", + "save_array", + "save_group", + "tree", + "array", + "group", + "open_group", + "create", + "empty", + "empty_like", + "full", + "full_like", + "ones", + "ones_like", + "open_array", + "open_like", + "zeros", + "zeros_like", +] + # TODO: this type could use some more thought, noqa to avoid "Variable "asynchronous.ArrayLike" is not valid as a type" ArrayLike = Union[AsyncArray | Array | npt.NDArray[Any]] # noqa PathLike = str @@ -933,32 +961,3 @@ async def zeros_like(a: ArrayLike, **kwargs: Any) -> AsyncArray: """ like_kwargs = _like_args(a, kwargs) return await zeros(**like_kwargs) - - -__all__ = [ - "consolidate_metadata", - "copy", - "copy_all", - "copy_store", - "load", - "open", - "open_consolidated", - "save", - "save_array", - "save_group", - "tree", - "array", - "group", - "open_group", - "create", - "empty", - "empty_like", - "full", - "full_like", - "ones", - "ones_like", - "open_array", - "open_like", - "zeros", - "zeros_like", -] diff --git a/src/zarr/api/synchronous.py b/src/zarr/api/synchronous.py index 78621e5d1e..d3d674c3fd 100644 --- a/src/zarr/api/synchronous.py +++ b/src/zarr/api/synchronous.py @@ -10,6 +10,34 @@ from zarr.core.sync import sync from zarr.store import StoreLike +__all__ = [ + "consolidate_metadata", + "copy", + "copy_all", + "copy_store", + "load", + "open", + "open_consolidated", + "save", + "save_array", + "save_group", + "tree", + "array", + "group", + "open_group", + "create", + "empty", + "empty_like", + "full", + "full_like", + "ones", + "ones_like", + "open_array", + "open_like", + "zeros", + "zeros_like", +] + def consolidate_metadata(*args: Any, **kwargs: Any) -> Group: return Group(sync(async_api.consolidate_metadata(*args, **kwargs))) @@ -271,31 +299,3 @@ def zeros_like(a: async_api.ArrayLike, **kwargs: Any) -> Array: open_like.__doc__ = async_api.open_like.__doc__ zeros.__doc__ = async_api.zeros.__doc__ zeros_like.__doc__ = async_api.zeros_like.__doc__ - -__all__ = [ - "consolidate_metadata", - "copy", - "copy_all", - "copy_store", - "load", - "open", - "open_consolidated", - "save", - "save_array", - "save_group", - "tree", - "array", - "group", - "open_group", - "create", - "empty", - "empty_like", - "full", - "full_like", - "ones", - "ones_like", - "open_array", - "open_like", - "zeros", - "zeros_like", -] diff --git a/src/zarr/convenience.py b/src/zarr/convenience.py index 95269e951d..f0ff602d07 100644 --- a/src/zarr/convenience.py +++ b/src/zarr/convenience.py @@ -1,5 +1,33 @@ import warnings +from zarr.api.synchronous import ( + consolidate_metadata, + copy, + copy_all, + copy_store, + load, + open, + open_consolidated, + save, + save_array, + save_group, + tree, +) + +__all__ = [ + "open", + "save", + "load", + "save_array", + "save_group", + "copy", + "copy_all", + "copy_store", + "tree", + "consolidate_metadata", + "open_consolidated", +] + warnings.warn( "zarr.convenience is deprecated, use zarr.api.synchronous", DeprecationWarning, diff --git a/src/zarr/creation.py b/src/zarr/creation.py index 91de696a6b..aa4b5a8088 100644 --- a/src/zarr/creation.py +++ b/src/zarr/creation.py @@ -1,5 +1,35 @@ import warnings +from zarr.api.synchronous import ( + array, + create, + empty, + empty_like, + full, + full_like, + ones, + ones_like, + open_array, + open_like, + zeros, + zeros_like, +) + +__all__ = [ + "create", + "empty", + "zeros", + "ones", + "full", + "array", + "open_array", + "empty_like", + "zeros_like", + "ones_like", + "full_like", + "open_like", +] + warnings.warn( "zarr.creation is deprecated, use zarr.api.synchronous", DeprecationWarning, diff --git a/src/zarr/store/__init__.py b/src/zarr/store/__init__.py index bc5a0efab2..3a9e8201e8 100644 --- a/src/zarr/store/__init__.py +++ b/src/zarr/store/__init__.py @@ -1,6 +1,6 @@ -from zarr.store._local import LocalStore -from zarr.store._memory import MemoryStore -from zarr.store._remote import RemoteStore from zarr.store.common import StoreLike, StorePath, make_store_path +from zarr.store.local import LocalStore +from zarr.store.memory import MemoryStore +from zarr.store.remote import RemoteStore __all__ = ["StorePath", "StoreLike", "make_store_path", "RemoteStore", "LocalStore", "MemoryStore"] diff --git a/src/zarr/store/common.py b/src/zarr/store/common.py index 30ae3812cf..6a88de7760 100644 --- a/src/zarr/store/common.py +++ b/src/zarr/store/common.py @@ -8,8 +8,8 @@ from zarr.core.buffer import Buffer, default_buffer_prototype from zarr.core.common import ZARR_JSON, ZARRAY_JSON, ZGROUP_JSON, ZarrFormat from zarr.errors import ContainsArrayAndGroupError, ContainsArrayError, ContainsGroupError -from zarr.store._local import LocalStore -from zarr.store._memory import MemoryStore +from zarr.store.local import LocalStore +from zarr.store.memory import MemoryStore if TYPE_CHECKING: from zarr.core.buffer import BufferPrototype diff --git a/src/zarr/store/_local.py b/src/zarr/store/local.py similarity index 100% rename from src/zarr/store/_local.py rename to src/zarr/store/local.py diff --git a/src/zarr/store/_memory.py b/src/zarr/store/memory.py similarity index 100% rename from src/zarr/store/_memory.py rename to src/zarr/store/memory.py diff --git a/src/zarr/store/_remote.py b/src/zarr/store/remote.py similarity index 100% rename from src/zarr/store/_remote.py rename to src/zarr/store/remote.py diff --git a/tests/v3/conftest.py b/tests/v3/conftest.py index acdd050fff..d8af484ee6 100644 --- a/tests/v3/conftest.py +++ b/tests/v3/conftest.py @@ -20,7 +20,7 @@ from hypothesis import HealthCheck, Verbosity, settings from zarr.store import LocalStore, MemoryStore, StorePath -from zarr.store._remote import RemoteStore +from zarr.store.remote import RemoteStore async def parse_store( diff --git a/tests/v3/test_indexing.py b/tests/v3/test_indexing.py index 45353b1f5e..7895151b5f 100644 --- a/tests/v3/test_indexing.py +++ b/tests/v3/test_indexing.py @@ -22,8 +22,8 @@ replace_ellipsis, ) from zarr.registry import get_ndbuffer_class -from zarr.store._memory import MemoryStore from zarr.store.common import StorePath +from zarr.store.memory import MemoryStore @pytest.fixture diff --git a/tests/v3/test_store/test_core.py b/tests/v3/test_store/test_core.py index 2142a5ebcd..23821acfa6 100644 --- a/tests/v3/test_store/test_core.py +++ b/tests/v3/test_store/test_core.py @@ -2,9 +2,9 @@ import pytest -from zarr.store._local import LocalStore -from zarr.store._memory import MemoryStore from zarr.store.common import make_store_path +from zarr.store.local import LocalStore +from zarr.store.memory import MemoryStore async def test_make_store_path(tmpdir) -> None: diff --git a/tests/v3/test_store/test_local.py b/tests/v3/test_store/test_local.py index fc57d4db9f..8afa4fef3a 100644 --- a/tests/v3/test_store/test_local.py +++ b/tests/v3/test_store/test_local.py @@ -3,7 +3,7 @@ import pytest from zarr.core.buffer import Buffer -from zarr.store._local import LocalStore +from zarr.store.local import LocalStore from zarr.testing.store import StoreTests diff --git a/tests/v3/test_store/test_memory.py b/tests/v3/test_store/test_memory.py index f71c971114..51ecf46709 100644 --- a/tests/v3/test_store/test_memory.py +++ b/tests/v3/test_store/test_memory.py @@ -3,7 +3,7 @@ import pytest from zarr.core.buffer import Buffer -from zarr.store._memory import MemoryStore +from zarr.store.memory import MemoryStore from zarr.testing.store import StoreTests From bd94189ea7a09e880d632ac1689e8437ec51d8a9 Mon Sep 17 00:00:00 2001 From: Joseph Hamman Date: Tue, 13 Aug 2024 16:17:22 -0700 Subject: [PATCH 5/5] move __all__s --- src/zarr/registry.py | 25 ++++++++++++------------- src/zarr/testing/buffer.py | 14 +++++++------- src/zarr/testing/store.py | 6 +++--- src/zarr/testing/utils.py | 5 ++--- 4 files changed, 24 insertions(+), 26 deletions(-) diff --git a/src/zarr/registry.py b/src/zarr/registry.py index b774c620da..cde3b7d848 100644 --- a/src/zarr/registry.py +++ b/src/zarr/registry.py @@ -13,6 +13,18 @@ from zarr.abc.codec import Codec, CodecPipeline from zarr.core.buffer import Buffer, NDBuffer +__all__ = [ + "Registry", + "register_codec", + "register_pipeline", + "register_buffer", + "register_ndbuffer", + "get_codec_class", + "get_pipeline_class", + "get_buffer_class", + "get_ndbuffer_class", +] + T = TypeVar("T") @@ -178,16 +190,3 @@ def get_ndbuffer_class(reload_config: bool = False) -> type[NDBuffer]: _collect_entrypoints() - - -__all__ = [ - "Registry", - "register_codec", - "register_pipeline", - "register_buffer", - "register_ndbuffer", - "get_codec_class", - "get_pipeline_class", - "get_buffer_class", - "get_ndbuffer_class", -] diff --git a/src/zarr/testing/buffer.py b/src/zarr/testing/buffer.py index 244736c925..ee170a5dd3 100644 --- a/src/zarr/testing/buffer.py +++ b/src/zarr/testing/buffer.py @@ -14,6 +14,13 @@ from typing_extensions import Self +__all__ = [ + "TestBuffer", + "NDBufferUsingTestNDArrayLike", + "StoreExpectingTestBuffer", +] + + class TestNDArrayLike(np.ndarray): """An example of a ndarray-like class""" @@ -64,10 +71,3 @@ async def get( if ret is not None: assert isinstance(ret, prototype.buffer) return ret - - -__all__ = [ - "TestBuffer", - "NDBufferUsingTestNDArrayLike", - "StoreExpectingTestBuffer", -] diff --git a/src/zarr/testing/store.py b/src/zarr/testing/store.py index e739aa9a40..ebef4824f7 100644 --- a/src/zarr/testing/store.py +++ b/src/zarr/testing/store.py @@ -7,6 +7,9 @@ from zarr.store._utils import _normalize_interval_index from zarr.testing.utils import assert_bytes_equal +__all__ = ["StoreTests"] + + S = TypeVar("S", bound=Store) @@ -199,6 +202,3 @@ async def test_list_dir(self, store: S) -> None: keys_observed = [k async for k in store.list_dir("foo/")] assert len(keys_expected) == len(keys_observed), keys_observed assert set(keys_observed) == set(keys_expected), keys_observed - - -__all__ = ["StoreTests"] diff --git a/src/zarr/testing/utils.py b/src/zarr/testing/utils.py index 73d035b6cd..3a70f96d44 100644 --- a/src/zarr/testing/utils.py +++ b/src/zarr/testing/utils.py @@ -3,6 +3,8 @@ from zarr.core.buffer import Buffer from zarr.core.common import BytesLike +__all__ = ["assert_bytes_equal"] + def assert_bytes_equal(b1: Buffer | BytesLike | None, b2: Buffer | BytesLike | None) -> None: """Help function to assert if two bytes-like or Buffers are equal @@ -16,6 +18,3 @@ def assert_bytes_equal(b1: Buffer | BytesLike | None, b2: Buffer | BytesLike | N if isinstance(b2, Buffer): b2 = b2.to_bytes() assert b1 == b2 - - -__all__ = ["assert_bytes_equal"]