Skip to content
Merged
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
17 changes: 8 additions & 9 deletions dandi/files/zarr.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,11 +275,14 @@ def _ts_validate_zarr3_array(
class LocalZarrEntry(BasePath):
"""A file or directory within a `ZarrAsset`"""

#: The path to the actual file or directory on disk
filepath: Path
#: The path to the root of the Zarr file tree
zarr_basepath: Path

@property
def filepath(self) -> Path:
"""The path to the actual file or directory on disk"""
return self.zarr_basepath.joinpath(*self.parts)

def _get_subpath(self, name: str) -> LocalZarrEntry:
if not name or "/" in name:
raise ValueError(f"Invalid path component: {name!r}")
Expand All @@ -288,16 +291,14 @@ def _get_subpath(self, name: str) -> LocalZarrEntry:
elif name == "..":
return self.parent
else:
return replace(
self, filepath=self.filepath / name, parts=self.parts + (name,)
)
return replace(self, parts=self.parts + (name,))

@property
def parent(self) -> LocalZarrEntry:
if self.is_root():
return self
else:
return replace(self, filepath=self.filepath.parent, parts=self.parts[:-1])
return replace(self, parts=self.parts[:-1])

def exists(self) -> bool:
return os.path.lexists(self.filepath)
Expand Down Expand Up @@ -390,9 +391,7 @@ def filetree(self) -> LocalZarrEntry:
The `LocalZarrEntry` for the root of the hierarchy of files within the
Zarr asset
"""
return LocalZarrEntry(
filepath=self.filepath, zarr_basepath=self.filepath, parts=()
)
return LocalZarrEntry(zarr_basepath=self.filepath, parts=())

def stat(self) -> ZarrStat:
"""Return various details about the Zarr asset"""
Expand Down
Loading