From 159e5ae742ef640d0104673d1cebc154c5982f73 Mon Sep 17 00:00:00 2001 From: David Michaels Date: Thu, 22 Aug 2024 23:52:45 -0400 Subject: [PATCH] Modified structured_data hook interface slightly to check for and call the "finish" attribute/callable hook. --- CHANGELOG.rst | 4 ++-- dcicutils/structured_data.py | 6 +++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index f3e8e651c..6926218df 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -10,8 +10,8 @@ Change Log ====== * 2024-08-22 (dmichaels) -* Modified structured_data hook interface slightly to - check for and call the "finish" attribute/callable hook. +* Modified structured_data property hook for "finish" attribute/callable. +* Added sheet hook to structured_data. * Added portal_utils.Portal.head method. diff --git a/dcicutils/structured_data.py b/dcicutils/structured_data.py index 74733061f..945723040 100644 --- a/dcicutils/structured_data.py +++ b/dcicutils/structured_data.py @@ -58,6 +58,7 @@ def __init__(self, file: Optional[str] = None, portal: Optional[Union[VirtualApp norefs: bool = False, merge: bool = False, progress: Optional[Callable] = None, validator_hook: Optional[Callable] = None, + validator_sheet_hook: Optional[Callable] = None, debug_sleep: Optional[str] = None) -> None: self._progress = progress if callable(progress) else None self._data = {} @@ -76,7 +77,8 @@ def __init__(self, file: Optional[str] = None, portal: Optional[Union[VirtualApp self._autoadd_properties = autoadd if isinstance(autoadd, dict) and autoadd else None self._norefs = True if norefs is True else False self._merge = True if merge is True else False # New merge functionality (2024-05-25) - self._validator_hook = validator_hook if callable(validator_hook) else None # Testing support (2024-06-12) + self._validator_hook = validator_hook if callable(validator_hook) else None + self._validator_sheet_hook = validator_sheet_hook if callable(validator_sheet_hook) else None self._debug_sleep = None if debug_sleep: try: @@ -316,6 +318,8 @@ def get_counts() -> Tuple[int, int]: order = {Schema.type_name(key): index for index, key in enumerate(self._order)} if self._order else {} for sheet_name in sorted(excel.sheet_names, key=lambda key: order.get(Schema.type_name(key), sys.maxsize)): self._load_reader(excel.sheet_reader(sheet_name), type_name=Schema.type_name(sheet_name)) + if self._validator_sheet_hook: + self._validator_sheet_hook(self, sheet_name, self.data[sheet_name]) # TODO: Do we really need progress reporting for the below? # Check for unresolved reference errors which really are not because of ordering. # Yes such internal references will be handled correctly on actual database update via snovault.loadxl.