Don't calculate private attributes each time the Hierarchy's properties

are called
This commit is contained in:
Eric Torres 2019-04-14 09:28:41 -07:00
parent 147d29a633
commit 7bff0f806c
2 changed files with 7 additions and 3 deletions

View File

@ -48,6 +48,8 @@ class Hierarchy(PathLike):
:type dest: str or path-like object
"""
self._path = Path(dest).resolve()
self._metadata_path = self._path / ".metadata"
self._name = self._path.name
def __fspath__(self):
return str(self._path)
@ -70,7 +72,7 @@ class Hierarchy(PathLike):
:rtype: str
"""
return self._path.name
return self._name
@property
def metadata_path(self):
@ -78,7 +80,7 @@ class Hierarchy(PathLike):
:rtype: path-like object
"""
return self._path / ".metadata"
return self._metadata_path
def gen_metadata(self):
"""Generate metadata for this repository.

View File

@ -32,6 +32,8 @@ class Snapshot(Hierarchy):
"""Default constructor for the Snapshot class."""
super().__init__(path)
self._pkg_dir = self.path / "pkg"
def __repr__(self):
"""Return a string representation of this Snapshot."""
return f"{self.__class__.__name__}('{self.name}')"
@ -42,7 +44,7 @@ class Snapshot(Hierarchy):
:rtype: path-like object
"""
return self.path / "pkg"
return self._pkg_dir
def gen_metadata(self):
"""Generate metadata for this repository.