From fcb479ac271fd83fd40bd2058b26e6c119cea768 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristian=20Zar=C4=99bski?= Date: Wed, 5 Jun 2024 09:54:13 +0100 Subject: [PATCH 1/3] Add path object compatibility to add_process --- simvue/executor.py | 2 +- simvue/run.py | 21 +++++++++++++++++---- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/simvue/executor.py b/simvue/executor.py index f4710137..2aad96b3 100644 --- a/simvue/executor.py +++ b/simvue/executor.py @@ -106,7 +106,7 @@ def add_process( completion_callback: typing.Optional[ typing.Callable[[int, str, str], None] ] = None, - completion_trigger: multiprocessing.synchronize.Event, + completion_trigger: typing.Optional[multiprocessing.synchronize.Event] = None, **kwargs, ) -> None: """Add a process to be executed to the executor. diff --git a/simvue/run.py b/simvue/run.py index 78376811..2c2e06af 100644 --- a/simvue/run.py +++ b/simvue/run.py @@ -11,6 +11,7 @@ import json import logging import mimetypes +import pathlib import multiprocessing.synchronize import threading import humanfriendly @@ -609,8 +610,8 @@ def add_process( identifier: str, *cmd_args, executable: typing.Optional[str] = None, - script: typing.Optional[str] = None, - input_file: typing.Optional[str] = None, + script: typing.Optional[typing.Union[str, pathlib.Path]] = None, + input_file: typing.Optional[typing.Union[str, pathlib.Path]] = None, completion_callback: typing.Optional[ typing.Callable[[int, str, str], None] ] = None, @@ -683,6 +684,18 @@ def callback_function(status_code: int, std_out: str, std_err: str) -> None: _cmd_list: typing.List[str] = [] _pos_args = list(cmd_args) + if script: + if isinstance(script, str): + script = pathlib.Path(script) + if not script.exists(): + self._error(f"Script '{script}' not found.") + + if input_file: + if isinstance(input_file, str): + input_file = pathlib.Path(input_file) + if not input_file.exists(): + self._error(f"Script '{input_file}' not found.") + # Assemble the command for saving to metadata as string if executable: _cmd_list += [executable] @@ -715,8 +728,8 @@ def callback_function(status_code: int, std_out: str, std_err: str) -> None: identifier, *_pos_args, executable=executable, - script=script, - input_file=input_file, + script=f"{script}", + input_file=f"{input_file}", completion_callback=completion_callback, completion_trigger=completion_trigger, env=env, From 2c5cea699326fb85615a8a510c112a159baacda8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristian=20Zar=C4=99bski?= Date: Wed, 5 Jun 2024 09:55:52 +0100 Subject: [PATCH 2/3] Validate file path for add_process --- simvue/run.py | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/simvue/run.py b/simvue/run.py index 2c2e06af..0fdd05d7 100644 --- a/simvue/run.py +++ b/simvue/run.py @@ -11,7 +11,6 @@ import json import logging import mimetypes -import pathlib import multiprocessing.synchronize import threading import humanfriendly @@ -610,8 +609,8 @@ def add_process( identifier: str, *cmd_args, executable: typing.Optional[str] = None, - script: typing.Optional[typing.Union[str, pathlib.Path]] = None, - input_file: typing.Optional[typing.Union[str, pathlib.Path]] = None, + script: typing.Optional[pydantic.FilePath] = None, + input_file: typing.Optional[pydantic.FilePath] = None, completion_callback: typing.Optional[ typing.Callable[[int, str, str], None] ] = None, @@ -684,18 +683,6 @@ def callback_function(status_code: int, std_out: str, std_err: str) -> None: _cmd_list: typing.List[str] = [] _pos_args = list(cmd_args) - if script: - if isinstance(script, str): - script = pathlib.Path(script) - if not script.exists(): - self._error(f"Script '{script}' not found.") - - if input_file: - if isinstance(input_file, str): - input_file = pathlib.Path(input_file) - if not input_file.exists(): - self._error(f"Script '{input_file}' not found.") - # Assemble the command for saving to metadata as string if executable: _cmd_list += [executable] From 49fbcdd9e705994246e9b9ff1956308a78f5f5d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristian=20Zar=C4=99bski?= Date: Fri, 7 Jun 2024 09:05:27 +0100 Subject: [PATCH 3/3] Fix typing of paths in add_process --- simvue/executor.py | 5 +++-- simvue/run.py | 6 +++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/simvue/executor.py b/simvue/executor.py index 2aad96b3..8373433b 100644 --- a/simvue/executor.py +++ b/simvue/executor.py @@ -16,6 +16,7 @@ import multiprocessing import os import subprocess +import pathlib import time import typing @@ -100,8 +101,8 @@ def add_process( identifier: str, *args, executable: typing.Optional[str] = None, - script: typing.Optional[str] = None, - input_file: typing.Optional[str] = None, + script: typing.Optional[pathlib.Path] = None, + input_file: typing.Optional[pathlib.Path] = None, env: typing.Optional[typing.Dict[str, str]] = None, completion_callback: typing.Optional[ typing.Callable[[int, str, str], None] diff --git a/simvue/run.py b/simvue/run.py index 4ee504d0..ceb97508 100644 --- a/simvue/run.py +++ b/simvue/run.py @@ -609,7 +609,7 @@ def add_process( self, identifier: str, *cmd_args, - executable: typing.Optional[str] = None, + executable: typing.Optional[typing.Union[str]] = None, script: typing.Optional[pydantic.FilePath] = None, input_file: typing.Optional[pydantic.FilePath] = None, completion_callback: typing.Optional[ @@ -716,8 +716,8 @@ def callback_function(status_code: int, std_out: str, std_err: str) -> None: identifier, *_pos_args, executable=executable, - script=f"{script}", - input_file=f"{input_file}", + script=script, + input_file=input_file, completion_callback=completion_callback, completion_trigger=completion_trigger, env=env,