diff --git a/core/correctness/validation.py b/core/correctness/validation.py index f542387..5576084 100644 --- a/core/correctness/validation.py +++ b/core/correctness/validation.py @@ -3,7 +3,8 @@ from inspect import signature from os.path import sep, exists, isfile, isdir, dirname from typing import Any, _SpecialForm, Union, Tuple, get_origin, get_args -from core.correctness.vars import VALID_PATH_CHARS, get_not_imp_msg, EVENT_TYPE +from core.correctness.vars import VALID_PATH_CHARS, get_not_imp_msg, \ + EVENT_TYPE, EVENT_PATH def check_type(variable:Any, expected_type:type, alt_types:list[type]=[], or_none:bool=False)->None: @@ -183,3 +184,5 @@ def valid_event(event)->None: check_type(event, dict) if not EVENT_TYPE in event.keys(): raise KeyError(f"Events require key '{EVENT_TYPE}'") + if not EVENT_PATH in event.keys(): + raise KeyError(f"Events require key '{EVENT_PATH}'") diff --git a/core/correctness/vars.py b/core/correctness/vars.py index 2682ab6..81ad52c 100644 --- a/core/correctness/vars.py +++ b/core/correctness/vars.py @@ -189,8 +189,8 @@ APPENDING_NOTEBOOK = { # meow events EVENT_TYPE = "meow_event_type" +EVENT_PATH = "event_path" WATCHDOG_TYPE = "watchdog" -WATCHDOG_SRC = "src_path" WATCHDOG_BASE = "monitor_base" WATCHDOG_RULE = "rule_name" diff --git a/core/functionality.py b/core/functionality.py index c3568d2..f062c46 100644 --- a/core/functionality.py +++ b/core/functionality.py @@ -16,7 +16,7 @@ from core.correctness.validation import check_type, valid_existing_file_path, \ valid_path from core.correctness.vars import CHAR_LOWERCASE, CHAR_UPPERCASE, \ VALID_CHANNELS, HASH_BUFFER_SIZE, SHA256, DEBUG_WARNING, DEBUG_INFO, \ - EVENT_TYPE + EVENT_TYPE, EVENT_PATH def generate_id(prefix:str="", length:int=16, existing_ids:list[str]=[], charset:str=CHAR_UPPERCASE+CHAR_LOWERCASE, attempts:int=24): @@ -241,6 +241,6 @@ def print_debug(print_target, debug_level, msg, level)->None: status = "WARNING" print(f"{status}: {msg}", file=print_target) -def create_event(event_type:str, source:dict[Any,Any]={})->dict[Any,Any]: - return {**source, EVENT_TYPE: event_type} +def create_event(event_type:str, path:str, source:dict[Any,Any]={})->dict[Any,Any]: + return {**source, EVENT_PATH: path, EVENT_TYPE: event_type} diff --git a/patterns/file_event_pattern.py b/patterns/file_event_pattern.py index 7cbaec8..e9f83b1 100644 --- a/patterns/file_event_pattern.py +++ b/patterns/file_event_pattern.py @@ -18,7 +18,7 @@ from core.correctness.validation import check_type, valid_string, \ from core.correctness.vars import VALID_RECIPE_NAME_CHARS, \ VALID_VARIABLE_NAME_CHARS, FILE_EVENTS, FILE_CREATE_EVENT, \ FILE_MODIFY_EVENT, FILE_MOVED_EVENT, DEBUG_INFO, WATCHDOG_TYPE, \ - WATCHDOG_SRC, WATCHDOG_RULE, WATCHDOG_BASE, FILE_RETROACTIVE_EVENT + WATCHDOG_RULE, WATCHDOG_BASE, FILE_RETROACTIVE_EVENT, EVENT_PATH from core.functionality import print_debug, create_event from core.meow import BasePattern, BaseMonitor, BaseRule, BaseRecipe, \ create_rule @@ -189,11 +189,10 @@ class WatchdogMonitor(BaseMonitor): if direct_hit or recursive_hit: meow_event = create_event( - WATCHDOG_TYPE, { - WATCHDOG_SRC: event.src_path, - WATCHDOG_BASE: self.base_dir, - WATCHDOG_RULE: rule - }) + WATCHDOG_TYPE, + event.src_path, + { WATCHDOG_BASE: self.base_dir, WATCHDOG_RULE: rule } + ) print_debug(self._print_target, self.debug_level, f"Event at {src_path} of type {event_type} hit rule " f"{rule.name}", DEBUG_INFO) @@ -418,11 +417,10 @@ class WatchdogMonitor(BaseMonitor): for globble in globbed: meow_event = create_event( - WATCHDOG_TYPE, { - WATCHDOG_SRC: globble, - WATCHDOG_BASE: self.base_dir, - WATCHDOG_RULE: rule - }) + WATCHDOG_TYPE, + globble, + { WATCHDOG_BASE: self.base_dir, WATCHDOG_RULE: rule } + ) print_debug(self._print_target, self.debug_level, f"Retroactive event for file at at {globble} hit rule " f"{rule.name}", DEBUG_INFO) diff --git a/recipes/jupyter_notebook_recipe.py b/recipes/jupyter_notebook_recipe.py index 0361be3..6ed53ec 100644 --- a/recipes/jupyter_notebook_recipe.py +++ b/recipes/jupyter_notebook_recipe.py @@ -18,7 +18,7 @@ from core.correctness.validation import check_type, valid_string, \ setup_debugging from core.correctness.vars import VALID_VARIABLE_NAME_CHARS, VALID_CHANNELS, \ SHA256, DEBUG_ERROR, DEBUG_WARNING, DEBUG_INFO, WATCHDOG_TYPE, \ - WATCHDOG_SRC, WATCHDOG_BASE, WATCHDOG_RULE + WATCHDOG_BASE, WATCHDOG_RULE, EVENT_PATH from core.functionality import wait, get_file_hash, generate_id, make_dir, \ write_yaml, write_notebook, get_file_hash, parameterize_jupyter_notebook, \ print_debug @@ -118,9 +118,9 @@ class PapermillHandler(BaseHandler): # TODO finish implementation and test print_debug(self._print_target, self.debug_level, - f"Handling event {event[WATCHDOG_SRC]}", DEBUG_INFO) + f"Handling event {event[EVENT_PATH]}", DEBUG_INFO) - file_hash = get_file_hash(event[WATCHDOG_SRC], SHA256) + file_hash = get_file_hash(event[EVENT_PATH], SHA256) rule = event[WATCHDOG_RULE] yaml_dict = {} @@ -128,7 +128,7 @@ class PapermillHandler(BaseHandler): yaml_dict[var] = val for var, val in rule.pattern.outputs.items(): yaml_dict[var] = val - yaml_dict[rule.pattern.triggering_file] = event[WATCHDOG_SRC] + yaml_dict[rule.pattern.triggering_file] = event[EVENT_PATH] if not rule.pattern.sweep: waiting_for_threaded_resources = True @@ -203,7 +203,7 @@ class PapermillHandler(BaseHandler): JOB_PATTERN: event[WATCHDOG_RULE].pattern, JOB_RECIPE: event[WATCHDOG_RULE].recipe, JOB_RULE: event[WATCHDOG_RULE].name, - JOB_PATH: event[WATCHDOG_SRC], + JOB_PATH: event[EVENT_PATH], JOB_HASH: triggerfile_hash, JOB_STATUS: STATUS_QUEUED, JOB_CREATE_TIME: datetime.now(), @@ -211,7 +211,7 @@ class PapermillHandler(BaseHandler): } print_debug(self._print_target, self.debug_level, - f"Creating job for event at {event[WATCHDOG_SRC]} with ID " + f"Creating job for event at {event[EVENT_PATH]} with ID " f"{job_dict[JOB_ID]}", DEBUG_INFO) self.add_job(job_dict[JOB_ID]) @@ -219,7 +219,7 @@ class PapermillHandler(BaseHandler): yaml_dict = self.replace_keywords( yaml_dict, job_dict[JOB_ID], - event[WATCHDOG_SRC], + event[EVENT_PATH], event[WATCHDOG_BASE] )