Skip to content

Commit 9706ec6

Browse files
authored
Merge pull request #398 from simvue-io/hotfix/non-color-mode
Added no color mode
2 parents bdae56a + fd6007f commit 9706ec6

File tree

2 files changed

+23
-13
lines changed

2 files changed

+23
-13
lines changed

simvue/run.py

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ def __init__(
105105
self._executor = Executor(self)
106106
self._dispatcher: typing.Optional[DispatcherBaseClass] = None
107107
self._id: typing.Optional[str] = None
108+
self._term_color: bool = True
108109
self._suppress_errors: bool = False
109110
self._queue_blocking: bool = False
110111
self._status: typing.Optional[
@@ -187,10 +188,10 @@ def __exit__(
187188
if _error_msg:
188189
_error_msg = f":\n{_error_msg}"
189190
click.secho(
190-
"Simvue process executor terminated with non-zero exit status "
191+
"[simvue] Process executor terminated with non-zero exit status "
191192
f"{_non_zero}{_error_msg}",
192-
fg="red",
193-
bold=True,
193+
fg="red" if self._term_color else None,
194+
bold=self._term_color,
194195
)
195196
sys.exit(_non_zero)
196197

@@ -478,6 +479,7 @@ def init(
478479
visibility: typing.Union[
479480
typing.Literal["public", "tenant"], list[str], None
480481
] = None,
482+
no_color: bool = False,
481483
) -> bool:
482484
"""Initialise a Simvue run
483485
@@ -507,12 +509,15 @@ def init(
507509
* public - run viewable to all.
508510
* tenant - run viewable to all within the current tenant.
509511
* A list of usernames with which to share this run
512+
no_color : bool, optional
513+
disable terminal colors. Default False.
510514
511515
Returns
512516
-------
513517
bool
514518
whether the initialisation was successful
515519
"""
520+
self._term_color = not no_color
516521

517522
if isinstance(visibility, str) and visibility not in ("public", "tenant"):
518523
self._error(
@@ -594,11 +599,15 @@ def init(
594599
self._start()
595600

596601
if self._mode == "online":
597-
click.secho(f"[simvue] Run {self._name} created", bold=True, fg="green")
602+
click.secho(
603+
f"[simvue] Run {self._name} created",
604+
bold=self._term_color,
605+
fg="green" if self._term_color else None,
606+
)
598607
click.secho(
599608
f"[simvue] Monitor in the UI at {self._url}/dashboard/runs/run/{self._id}",
600-
bold=True,
601-
fg="green",
609+
bold=self._term_color,
610+
fg="green" if self._term_color else None,
602611
)
603612

604613
return True
@@ -1205,9 +1214,9 @@ def save_file(
12051214

12061215
if not file_size:
12071216
click.secho(
1208-
"WARNING: saving zero-sized files not currently supported",
1209-
bold=True,
1210-
fg="yellow",
1217+
"[simvue] WARNING: saving zero-sized files not currently supported",
1218+
bold=self._term_color,
1219+
fg="yellow" if self._term_color else None,
12111220
)
12121221
return True
12131222

@@ -1393,10 +1402,10 @@ def close(self) -> bool:
13931402
if _error_msg:
13941403
_error_msg = f":\n{_error_msg}"
13951404
click.secho(
1396-
"Simvue process executor terminated with non-zero exit status "
1405+
"[simvue] Process executor terminated with non-zero exit status "
13971406
f"{_non_zero}{_error_msg}",
1398-
fg="red",
1399-
bold=True,
1407+
fg="red" if self._term_color else None,
1408+
bold=self._term_color,
14001409
)
14011410
sys.exit(_non_zero)
14021411

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)