diff --git a/.github/workflows/api_tests.yml b/.github/workflows/api_tests.yml index 310b113c2..eea5da5c7 100644 --- a/.github/workflows/api_tests.yml +++ b/.github/workflows/api_tests.yml @@ -107,11 +107,12 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip + pip install -r requirements.txt pip install -r requirements-dev.txt - working-directory: openc3-cosmos-script-runner-api + working-directory: openc3/python - name: Lint with ruff run: | - ruff --format=github scripts/*.py + ruff --config=../openc3/python/pyproject.toml --format=github scripts/*.py working-directory: openc3-cosmos-script-runner-api - name: Run unit tests run: | diff --git a/openc3-cosmos-script-runner-api/scripts/run_script.py b/openc3-cosmos-script-runner-api/scripts/run_script.py index 0f2f2e0c3..fc5ab8541 100644 --- a/openc3-cosmos-script-runner-api/scripts/run_script.py +++ b/openc3-cosmos-script-runner-api/scripts/run_script.py @@ -164,7 +164,7 @@ def run_script_log(id, message, color="BLACK", message_log=True): | "open_file_dialog" | "open_files_dialog" ): - if running_script.prompt_id != None: + if running_script.prompt_id is not None: if ( "prompt_id" in parsed_cmd and running_script.prompt_id @@ -246,7 +246,7 @@ def run_script_log(id, message, color="BLACK", message_log=True): run_script_log( id, f"ERROR: Script command not handled: {msg['data']}", "RED" ) -except Exception as err: +except Exception: tb = traceback.format_exc() run_script_log(id, tb, "RED") finally: diff --git a/openc3-cosmos-script-runner-api/scripts/running_script.py b/openc3-cosmos-script-runner-api/scripts/running_script.py index 603a5ed49..98a933801 100644 --- a/openc3-cosmos-script-runner-api/scripts/running_script.py +++ b/openc3-cosmos-script-runner-api/scripts/running_script.py @@ -18,7 +18,6 @@ from openc3.utilities.string import build_timestamped_filename from openc3.utilities.bucket_utilities import BucketUtilities from openc3.script.storage import _get_storage_file -import re import linecache @@ -435,7 +434,11 @@ def unique_filename(self): return "Untitled" + str(RunningScript.id) def stop_message_log(self): - metadata = {"id": self.id, "user": self.details["user"], "scriptname": self.unique_filename()} + metadata = { + "id": self.id, + "user": self.details["user"], + "scriptname": self.unique_filename(), + } if RunningScript.my_message_log: RunningScript.my_message_log.stop(True, metadata=metadata) RunningScript.my_message_log = None @@ -448,7 +451,7 @@ def set_filename(self, filename): # Deal with breakpoints created under the previous filename. bkpt_filename = self.unique_filename() - if not bkpt_filename in RunningScript.breakpoints: + if bkpt_filename not in RunningScript.breakpoints: RunningScript.breakpoints[bkpt_filename] = RunningScript.breakpoints[ self.filename ] @@ -539,7 +542,7 @@ def exception_instrumentation(self, filename, line_number): if ( exc_type == StopScript or exc_type == SkipScript - or exc_type == SkipTestCase # DEPRECATED but still valid + or exc_type == SkipTestCase # DEPRECATED but still valid or not self.use_instrumentation ): raise exc_value @@ -597,20 +600,20 @@ def debug(self, debug_text): @classmethod def set_breakpoint(cls, filename, line_number): - if not filename in cls.breakpoints: + if filename not in cls.breakpoints: cls.breakpoints[filename] = {} cls.breakpoints[filename][line_number] = True @classmethod def clear_breakpoint(cls, filename, line_number): - if not filename in cls.breakpoints: + if filename not in cls.breakpoints: cls.breakpoints[filename] = {} if line_number in cls.breakpoints[filename]: del cls.breakpoints[filename][line_number] @classmethod def clear_breakpoints(cls, filename=None): - if filename == None or filename == "": + if filename is None or filename == "": cls.breakpoints = {} else: if filename in cls.breakpoints: @@ -679,7 +682,7 @@ def handle_output_io(self, filename=None, line_number=None): out_line = json_hash["log"] if "message" in json_hash: out_line = json_hash["message"] - except: + except Exception: # Regular output pass @@ -722,10 +725,6 @@ def handle_output_io(self, filename=None, line_number=None): # Add to the message log self.message_log().write(lines_to_write) - def graceful_kill(self): - # Just to avoid warning - pass - def wait_for_go_or_stop(self, error=None, prompt=None): count = -1 self.go = False @@ -1098,7 +1097,7 @@ def run_text( def handle_potential_tab_change(self, filename): # Make sure the correct file is shown in script runner if self.current_file != filename: - if not filename in self.call_stack: + if filename not in self.call_stack: self.call_stack.append(filename) self.load_file_into_script(filename) self.current_file = filename diff --git a/openc3-cosmos-script-runner-api/scripts/script_instrumentor.py b/openc3-cosmos-script-runner-api/scripts/script_instrumentor.py index 5f71e177d..91649812a 100644 --- a/openc3-cosmos-script-runner-api/scripts/script_instrumentor.py +++ b/openc3-cosmos-script-runner-api/scripts/script_instrumentor.py @@ -20,6 +20,7 @@ # For details on the AST, see https://docs.python.org/3/library/ast.html # and https://greentreesnakes.readthedocs.io/en/latest/nodes.html + # This class is used to instrument a Python script with calls to a # RunningScript instance. The RunningScript instance is used to # track the execution of the script, and can be used to pause and