Skip to content

Commit

Permalink
Modified structured_data hook interface slightly to check for and cal…
Browse files Browse the repository at this point in the history
…l the "finish" attribute/callable hook.
  • Loading branch information
dmichaels-harvard committed Aug 23, 2024
1 parent 2b3eaa0 commit 159e5ae
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.


Expand Down
6 changes: 5 additions & 1 deletion dcicutils/structured_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}
Expand All @@ -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:
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 159e5ae

Please sign in to comment.