Skip to content

Commit 0bc9365

Browse files
committed
Merge branch 'dev' into feature/auto-abort
2 parents f1d6f49 + 81de47e commit 0bc9365

File tree

3 files changed

+27
-16
lines changed

3 files changed

+27
-16
lines changed

simvue/executor.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import multiprocessing
1717
import os
1818
import subprocess
19+
import pathlib
1920
import time
2021
import typing
2122

@@ -100,13 +101,13 @@ def add_process(
100101
identifier: str,
101102
*args,
102103
executable: typing.Optional[str] = None,
103-
script: typing.Optional[str] = None,
104-
input_file: typing.Optional[str] = None,
104+
script: typing.Optional[pathlib.Path] = None,
105+
input_file: typing.Optional[pathlib.Path] = None,
105106
env: typing.Optional[typing.Dict[str, str]] = None,
106107
completion_callback: typing.Optional[
107108
typing.Callable[[int, str, str], None]
108109
] = None,
109-
completion_trigger: multiprocessing.synchronize.Event,
110+
completion_trigger: typing.Optional[multiprocessing.synchronize.Event] = None,
110111
**kwargs,
111112
) -> None:
112113
"""Add a process to be executed to the executor.

simvue/run.py

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ def __init__(
106106
self._executor = Executor(self)
107107
self._dispatcher: typing.Optional[DispatcherBaseClass] = None
108108
self._id: typing.Optional[str] = None
109+
self._term_color: bool = True
109110
self._suppress_errors: bool = False
110111
self._queue_blocking: bool = False
111112
self._status: typing.Optional[
@@ -191,8 +192,8 @@ def __exit__(
191192
click.secho(
192193
"[simvue] Process executor terminated with non-zero exit status "
193194
f"{_non_zero}{_error_msg}",
194-
fg="red",
195-
bold=True,
195+
fg="red" if self._term_color else None,
196+
bold=self._term_color,
196197
)
197198
sys.exit(_non_zero)
198199

@@ -504,6 +505,7 @@ def init(
504505
visibility: typing.Union[
505506
typing.Literal["public", "tenant"], list[str], None
506507
] = None,
508+
no_color: bool = False,
507509
) -> bool:
508510
"""Initialise a Simvue run
509511
@@ -531,12 +533,15 @@ def init(
531533
* public - run viewable to all.
532534
* tenant - run viewable to all within the current tenant.
533535
* A list of usernames with which to share this run
536+
no_color : bool, optional
537+
disable terminal colors. Default False.
534538
535539
Returns
536540
-------
537541
bool
538542
whether the initialisation was successful
539543
"""
544+
self._term_color = not no_color
540545

541546
if isinstance(visibility, str) and visibility not in ("public", "tenant"):
542547
self._error(
@@ -616,11 +621,15 @@ def init(
616621
self._start()
617622

618623
if self._mode == "online":
619-
click.secho(f"[simvue] Run {self._name} created", bold=True, fg="green")
624+
click.secho(
625+
f"[simvue] Run {self._name} created",
626+
bold=self._term_color,
627+
fg="green" if self._term_color else None,
628+
)
620629
click.secho(
621630
f"[simvue] Monitor in the UI at {self._url}/dashboard/runs/run/{self._id}",
622-
bold=True,
623-
fg="green",
631+
bold=self._term_color,
632+
fg="green" if self._term_color else None,
624633
)
625634

626635
return True
@@ -631,9 +640,9 @@ def add_process(
631640
self,
632641
identifier: str,
633642
*cmd_args,
634-
executable: typing.Optional[str] = None,
635-
script: typing.Optional[str] = None,
636-
input_file: typing.Optional[str] = None,
643+
executable: typing.Optional[typing.Union[str]] = None,
644+
script: typing.Optional[pydantic.FilePath] = None,
645+
input_file: typing.Optional[pydantic.FilePath] = None,
637646
completion_callback: typing.Optional[
638647
typing.Callable[[int, str, str], None]
639648
] = None,
@@ -1234,8 +1243,8 @@ def save_file(
12341243
if not file_size:
12351244
click.secho(
12361245
"[simvue] WARNING: saving zero-sized files not currently supported",
1237-
bold=True,
1238-
fg="yellow",
1246+
bold=self._term_color,
1247+
fg="yellow" if self._term_color else None,
12391248
)
12401249
return True
12411250

@@ -1423,8 +1432,8 @@ def close(self) -> bool:
14231432
click.secho(
14241433
"[simvue] Process executor terminated with non-zero exit status "
14251434
f"{_non_zero}{_error_msg}",
1426-
fg="red",
1427-
bold=True,
1435+
fg="red" if self._term_color else None,
1436+
bold=self._term_color,
14281437
)
14291438
sys.exit(_non_zero)
14301439

tests/refactor/conftest.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@ def setup_test_run(run: sv_run.Run, create_objects: bool, request: pytest.Fixtur
9191
tags=TEST_DATA["tags"],
9292
folder=TEST_DATA["folder"],
9393
visibility="tenant" if os.environ.get("CI") else None,
94-
retention_period="1 hour"
94+
retention_period="1 hour",
95+
no_color=True
9596
)
9697
run._dispatcher._max_buffer_size = MAX_BUFFER_SIZE
9798

0 commit comments

Comments
 (0)