From 2cd92c04fa28e2115d91b7c01bbf803e51421f2e Mon Sep 17 00:00:00 2001 From: PatchOfScotland Date: Fri, 13 Jan 2023 18:15:15 +0100 Subject: [PATCH] some cleanup of unneeded imports and other small cleanups --- core/functionality.py | 13 ++++------ core/meow.py | 10 ++++---- recipes/jupyter_notebook_recipe.py | 41 ------------------------------ tests/test_functionality.py | 8 ++---- tests/test_meow.py | 7 +---- tests/test_patterns.py | 7 +++-- tests/test_recipes.py | 2 -- 7 files changed, 16 insertions(+), 72 deletions(-) diff --git a/core/functionality.py b/core/functionality.py index 0042281..c3568d2 100644 --- a/core/functionality.py +++ b/core/functionality.py @@ -1,25 +1,22 @@ import copy import hashlib -import inspect import json import nbformat import os -import sys import yaml from multiprocessing.connection import Connection, wait as multi_wait from multiprocessing.queues import Queue from papermill.translators import papermill_translators -from typing import Any, Union +from typing import Any from random import SystemRandom -#from core.meow import BasePattern, BaseRecipe, BaseRule -from core.correctness.validation import check_type, valid_dict, valid_list, \ - valid_existing_file_path, valid_path +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_ERROR, \ - DEBUG_INFO, EVENT_TYPE + VALID_CHANNELS, HASH_BUFFER_SIZE, SHA256, DEBUG_WARNING, DEBUG_INFO, \ + EVENT_TYPE def generate_id(prefix:str="", length:int=16, existing_ids:list[str]=[], charset:str=CHAR_UPPERCASE+CHAR_LOWERCASE, attempts:int=24): diff --git a/core/meow.py b/core/meow.py index 1fa3550..77ca564 100644 --- a/core/meow.py +++ b/core/meow.py @@ -8,7 +8,7 @@ from typing import Any, Union from core.correctness.vars import VALID_RECIPE_NAME_CHARS, \ VALID_PATTERN_NAME_CHARS, VALID_RULE_NAME_CHARS, VALID_CHANNELS, \ - get_drt_imp_msg, DEBUG_WARNING, DEBUG_INFO, DEBUG_ERROR + get_drt_imp_msg, DEBUG_WARNING, DEBUG_INFO from core.correctness.validation import valid_string, check_type, \ check_implementation, valid_list, valid_dict, setup_debugging from core.functionality import print_debug, wait, generate_id @@ -208,8 +208,8 @@ class MeowRunner: def start(self)->None: self.monitor.start() - #if hasattr(self.handler, "start"): - # self.handler.start() + if hasattr(self.handler, "start"): + self.handler.start() if self._worker is None: self._worker = threading.Thread( @@ -228,8 +228,8 @@ class MeowRunner: def stop(self)->None: self.monitor.stop() - #if hasattr(self.handler, "stop"): - # self.handler.stop() + if hasattr(self.handler, "stop"): + self.handler.stop() if self._worker is None: msg = "Cannot stop thread that is not started." diff --git a/recipes/jupyter_notebook_recipe.py b/recipes/jupyter_notebook_recipe.py index ebc6f40..0361be3 100644 --- a/recipes/jupyter_notebook_recipe.py +++ b/recipes/jupyter_notebook_recipe.py @@ -114,47 +114,6 @@ class PapermillHandler(BaseHandler): print_debug(self._print_target, self.debug_level, "Created new PapermillHandler instance", DEBUG_INFO) -# def run(self)->None: -# all_inputs = self.inputs + [self._stop_pipe[0]] -# while True: -# ready = wait(all_inputs) -# -# if self._stop_pipe[0] in ready: -# return -# else: -# for input in self.inputs: -# if input in ready: -# message = input.recv() -# event = message -# self.handle(event) -# -# def start(self)->None: -# if self._worker is None: -# self._worker = threading.Thread( -# target=self.run, -# args=[]) -# self._worker.daemon = True -# self._worker.start() -# print_debug(self._print_target, self.debug_level, -# "Starting PapermillHandler run...", DEBUG_INFO) -# else: -# msg = "Repeated calls to start have no effect." -# print_debug(self._print_target, self.debug_level, -# msg, DEBUG_WARNING) -# raise RuntimeWarning(msg) -# -# def stop(self)->None: -# if self._worker is None: -# msg = "Cannot stop thread that is not started." -# print_debug(self._print_target, self.debug_level, -# msg, DEBUG_WARNING) -# raise RuntimeWarning(msg) -# else: -# self._stop_pipe[1].send(1) -# self._worker.join() -# print_debug(self._print_target, self.debug_level, -# "Worker thread stopped", DEBUG_INFO) - def handle(self, event:dict[Any,Any])->None: # TODO finish implementation and test diff --git a/tests/test_functionality.py b/tests/test_functionality.py index 6b4756f..0c8a471 100644 --- a/tests/test_functionality.py +++ b/tests/test_functionality.py @@ -6,14 +6,10 @@ from multiprocessing import Pipe, Queue from time import sleep from core.correctness.vars import CHAR_LOWERCASE, CHAR_UPPERCASE, \ - BAREBONES_NOTEBOOK, SHA256, TEST_MONITOR_BASE, COMPLETE_NOTEBOOK, \ - EVENT_TYPE + SHA256, TEST_MONITOR_BASE, COMPLETE_NOTEBOOK, EVENT_TYPE from core.functionality import generate_id, wait, get_file_hash, rmtree, \ make_dir, parameterize_jupyter_notebook, create_event -from core.meow import BaseRule -from patterns.file_event_pattern import FileEventPattern -from recipes.jupyter_notebook_recipe import JupyterNotebookRecipe - + class CorrectnessTests(unittest.TestCase): def setUp(self) -> None: diff --git a/tests/test_meow.py b/tests/test_meow.py index ea9dc60..bb961d8 100644 --- a/tests/test_meow.py +++ b/tests/test_meow.py @@ -2,8 +2,7 @@ import io import os import unittest - -from multiprocessing import Pipe + from time import sleep from typing import Any @@ -175,8 +174,6 @@ class MeowTests(unittest.TestCase): FullTestHandler() def testMeowRunner(self)->None: - #monitor_to_handler_reader, monitor_to_handler_writer = Pipe() - pattern_one = FileEventPattern( "pattern_one", "start/A.txt", "recipe_one", "infile", parameters={ @@ -260,8 +257,6 @@ class MeowTests(unittest.TestCase): self.assertEqual(data, "Initial Data\nA line from a test Pattern") def testMeowRunnerLinkeExecution(self)->None: - #monitor_to_handler_reader, monitor_to_handler_writer = Pipe() - pattern_one = FileEventPattern( "pattern_one", "start/A.txt", "recipe_one", "infile", parameters={ diff --git a/tests/test_patterns.py b/tests/test_patterns.py index ed30a11..907c75a 100644 --- a/tests/test_patterns.py +++ b/tests/test_patterns.py @@ -4,9 +4,9 @@ import unittest from multiprocessing import Pipe -from core.correctness.vars import FILE_EVENTS, FILE_CREATE_EVENT, \ - BAREBONES_NOTEBOOK, TEST_MONITOR_BASE, EVENT_TYPE, WATCHDOG_RULE, \ - WATCHDOG_BASE, WATCHDOG_SRC, WATCHDOG_TYPE +from core.correctness.vars import FILE_CREATE_EVENT, BAREBONES_NOTEBOOK, \ + TEST_MONITOR_BASE, EVENT_TYPE, WATCHDOG_RULE, WATCHDOG_BASE, \ + WATCHDOG_SRC, WATCHDOG_TYPE from core.functionality import rmtree, make_dir from core.meow import create_rules from patterns.file_event_pattern import FileEventPattern, WatchdogMonitor, \ @@ -171,7 +171,6 @@ class CorrectnessTests(unittest.TestCase): self.assertEqual(len(rules), 1) rule = rules[list(rules.keys())[0]] - # TODO fix this test wm.start() open(os.path.join(TEST_MONITOR_BASE, "A"), "w") diff --git a/tests/test_recipes.py b/tests/test_recipes.py index 2ddf9d1..57fa248 100644 --- a/tests/test_recipes.py +++ b/tests/test_recipes.py @@ -4,9 +4,7 @@ import jsonschema import os import unittest -from multiprocessing import Pipe from time import sleep -from watchdog.events import FileCreatedEvent from patterns.file_event_pattern import FileEventPattern from recipes.jupyter_notebook_recipe import JupyterNotebookRecipe, \