Skip to content

Commit 96bf2df

Browse files
authored
Merge pull request #1843 from dandi/refactor-localzarrentry-filepath-property
RF: Derive LocalZarrEntry.filepath from zarr_basepath and parts
2 parents 4a14a1f + af831f5 commit 96bf2df

1 file changed

Lines changed: 8 additions & 9 deletions

File tree

‎dandi/files/zarr.py‎

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -275,11 +275,14 @@ def _ts_validate_zarr3_array(
275275
class LocalZarrEntry(BasePath):
276276
"""A file or directory within a `ZarrAsset`"""
277277

278-
#: The path to the actual file or directory on disk
279-
filepath: Path
280278
#: The path to the root of the Zarr file tree
281279
zarr_basepath: Path
282280

281+
@property
282+
def filepath(self) -> Path:
283+
"""The path to the actual file or directory on disk"""
284+
return self.zarr_basepath.joinpath(*self.parts)
285+
283286
def _get_subpath(self, name: str) -> LocalZarrEntry:
284287
if not name or "/" in name:
285288
raise ValueError(f"Invalid path component: {name!r}")
@@ -288,16 +291,14 @@ def _get_subpath(self, name: str) -> LocalZarrEntry:
288291
elif name == "..":
289292
return self.parent
290293
else:
291-
return replace(
292-
self, filepath=self.filepath / name, parts=self.parts + (name,)
293-
)
294+
return replace(self, parts=self.parts + (name,))
294295

295296
@property
296297
def parent(self) -> LocalZarrEntry:
297298
if self.is_root():
298299
return self
299300
else:
300-
return replace(self, filepath=self.filepath.parent, parts=self.parts[:-1])
301+
return replace(self, parts=self.parts[:-1])
301302

302303
def exists(self) -> bool:
303304
return os.path.lexists(self.filepath)
@@ -390,9 +391,7 @@ def filetree(self) -> LocalZarrEntry:
390391
The `LocalZarrEntry` for the root of the hierarchy of files within the
391392
Zarr asset
392393
"""
393-
return LocalZarrEntry(
394-
filepath=self.filepath, zarr_basepath=self.filepath, parts=()
395-
)
394+
return LocalZarrEntry(zarr_basepath=self.filepath, parts=())
396395

397396
def stat(self) -> ZarrStat:
398397
"""Return various details about the Zarr asset"""

0 commit comments

Comments
 (0)