Skip to content

Commit fea7f91

Browse files
committed
Ignore special dotfiles when validating Zarr depth
1 parent ed0fab3 commit fea7f91

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

dandi/files/zarr.py

+7-5
Original file line numberDiff line numberDiff line change
@@ -220,11 +220,7 @@ def get_validation_errors(
220220
message="Zarr group is empty.",
221221
)
222222
]
223-
try:
224-
next(self.filepath.glob(f"*{os.sep}" + os.sep.join(["*"] * MAX_ZARR_DEPTH)))
225-
except StopIteration:
226-
pass
227-
else:
223+
if self._is_too_deep():
228224
msg = f"Zarr directory tree more than {MAX_ZARR_DEPTH} directories deep"
229225
if devel_debug:
230226
raise ValueError(msg)
@@ -246,6 +242,12 @@ def get_validation_errors(
246242
schema_version=schema_version, devel_debug=devel_debug
247243
)
248244

245+
def _is_too_deep(self) -> bool:
246+
for e in self.iterfiles():
247+
if len(e.parts) >= MAX_ZARR_DEPTH + 1:
248+
return True
249+
return False
250+
249251
def iter_upload(
250252
self,
251253
dandiset: RemoteDandiset,

dandi/tests/test_files.py

+18
Original file line numberDiff line numberDiff line change
@@ -392,3 +392,21 @@ def test_upload_zarr_with_excluded_dotfiles(
392392
"arr_1/.zarray",
393393
"arr_1/0",
394394
]
395+
396+
397+
def test_validate_deep_zarr(tmp_path: Path) -> None:
398+
zarr_path = tmp_path / "foo.zarr"
399+
zarr.save(zarr_path, np.arange(1000), np.arange(1000, 0, -1))
400+
mkpaths(zarr_path, "a/b/c/d/e/f/g.txt")
401+
zf = dandi_file(zarr_path)
402+
assert zf.get_validation_errors() == []
403+
mkpaths(zarr_path, "a/b/c/d/e/f/g/h.txt")
404+
assert [e.id for e in zf.get_validation_errors()] == ["zarr.tree_depth_exceeded"]
405+
406+
407+
def test_validate_zarr_deep_via_excluded_dotfiles(tmp_path: Path) -> None:
408+
zarr_path = tmp_path / "foo.zarr"
409+
zarr.save(zarr_path, np.arange(1000), np.arange(1000, 0, -1))
410+
mkpaths(zarr_path, ".git/a/b/c/d/e/f/g.txt")
411+
zf = dandi_file(zarr_path)
412+
assert zf.get_validation_errors() == []

0 commit comments

Comments
 (0)