Skip to content

Commit

Permalink
⚙️ fixed: split metadata management from init to method.
Browse files Browse the repository at this point in the history
  • Loading branch information
korawica committed Oct 19, 2024
1 parent 43ee1a9 commit 797430e
Showing 1 changed file with 22 additions and 11 deletions.
33 changes: 22 additions & 11 deletions src/ddeutil/io/register.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,15 +199,18 @@ def __init__(
self.__data: dict[str, Any] = self.pick(stage=self.stage)
if not self.__data:
raise StoreNotFound(
f"Config {self.name!r} "
f"Register name {self.name!r} "
f"{f'in domain {self.domain!r} ' if self.domain else ' '}"
f"does not exist in stage {self.stage!r}."
f"does not find data in stage: {self.stage!r}."
)

# NOTE: Running metadata tracking cache.
self.__manage_metadata()

def __manage_metadata(self):
self.meta: dict[str, Any] = METADATA.get(self.fullname, {})

# NOTE:
# Compare data from current stage and latest version in metadata.
# NOTE: Compare data from current stage and latest version in metadata.
self.changed: int = self.compare_data(
target=self.meta.get(self.stage, {})
)
Expand All @@ -216,19 +219,18 @@ def __init__(
# Update metadata if the configuration data does not exist, or it has
# any changes.
if self.changed == 99:
logger.info(
f"Configuration data with stage: {self.stage!r} does not "
f"exists in metadata ..."
logger.debug(
f"Data in stage: {self.stage!r} does not exists in metadata"
)
# TODO: Create metadata for caching value before compare data next
# FIXME: Create metadata for caching value before compare data next
# time. (It can be table on database or sqlite file.
# METADATA.update({"self.fullname": self.__data})
elif self.changed > 0:
logger.info(
logger.debug(
f"Should update metadata because diff level is {self.changed}."
)

# TODO: Remove this line when develop metadata feature in the next
# FIXME: Remove this line when develop metadata feature in the next
# release.
METADATA.pop(self.fullname, None)

Expand Down Expand Up @@ -260,6 +262,7 @@ def data(self, hashing: bool = False) -> dict[str, Any]:
:param hashing: A hashing flag that allow use hash function on the
context data.
:rtype: dict[str, Any]
"""
_data: dict[str, Any] = self.__data.copy()
if not self.stage or (self.stage == BASE_STAGE_DEFAULT):
Expand Down Expand Up @@ -306,6 +309,11 @@ def version(self, _next: bool = False) -> VerPackage:
return version.bump_patch()

def fmt(self, update: dict[str, Any] | None = None) -> FormatterGroup:
"""Return FormatterGroup object that passing ``self.timestamp`` and
``self.version`` values.
:rtype: FormatterGroup
"""
return self.fmt_group(
{
"timestamp": self.timestamp,
Expand Down Expand Up @@ -358,7 +366,10 @@ def __stage_files(
stage: str,
store: StoreFl,
) -> dict[int, StageFiles]:
"""Return mapping of StageFiles data."""
"""Return mapping of StageFiles data.
:rtype: dict[int, StageFiles]
"""
results: dict[int, StageFiles] = {}
for index, file in enumerate((_f.name for _f in store.ls()), start=1):
try:
Expand Down

0 comments on commit 797430e

Please sign in to comment.