Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/zarr/storage/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ def __init__(self, root: Path | str, *, mode: AccessModeLiteral = "r") -> None:
assert isinstance(root, Path)
self.root = root

async def _open(self) -> None:
if not self.mode.readonly:
self.root.mkdir(parents=True, exist_ok=True)
return await super()._open()

async def clear(self) -> None:
self._check_writable()
shutil.rmtree(self.root)
Expand Down
13 changes: 13 additions & 0 deletions tests/v3/test_store/test_local.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
from __future__ import annotations

from typing import TYPE_CHECKING

import pytest

import zarr
from zarr.core.buffer import Buffer, cpu
from zarr.storage.local import LocalStore
from zarr.testing.store import StoreTests

if TYPE_CHECKING:
import pathlib


class TestLocalStore(StoreTests[LocalStore, cpu.Buffer]):
store_cls = LocalStore
Expand Down Expand Up @@ -40,3 +46,10 @@ async def test_empty_with_empty_subdir(self, store: LocalStore) -> None:
assert await store.empty()
(store.root / "foo/bar").mkdir(parents=True)
assert await store.empty()

def test_creates_new_directory(self, tmp_path: pathlib.Path):
target = tmp_path.joinpath("a", "b", "c")
assert not target.exists()

store = self.store_cls(root=target, mode="w")
zarr.group(store=store)