Skip to content

Added no color mode #398

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 21 additions & 12 deletions simvue/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ def __init__(
self._executor = Executor(self)
self._dispatcher: typing.Optional[DispatcherBaseClass] = None
self._id: typing.Optional[str] = None
self._term_color: bool = True
self._suppress_errors: bool = False
self._queue_blocking: bool = False
self._status: typing.Optional[
Expand Down Expand Up @@ -187,10 +188,10 @@ def __exit__(
if _error_msg:
_error_msg = f":\n{_error_msg}"
click.secho(
"Simvue process executor terminated with non-zero exit status "
"[simvue] Process executor terminated with non-zero exit status "
f"{_non_zero}{_error_msg}",
fg="red",
bold=True,
fg="red" if self._term_color else None,
bold=self._term_color,
)
sys.exit(_non_zero)

Expand Down Expand Up @@ -478,6 +479,7 @@ def init(
visibility: typing.Union[
typing.Literal["public", "tenant"], list[str], None
] = None,
no_color: bool = False,
) -> bool:
"""Initialise a Simvue run

Expand Down Expand Up @@ -507,12 +509,15 @@ def init(
* public - run viewable to all.
* tenant - run viewable to all within the current tenant.
* A list of usernames with which to share this run
no_color : bool, optional
disable terminal colors. Default False.

Returns
-------
bool
whether the initialisation was successful
"""
self._term_color = not no_color

if isinstance(visibility, str) and visibility not in ("public", "tenant"):
self._error(
Expand Down Expand Up @@ -594,11 +599,15 @@ def init(
self._start()

if self._mode == "online":
click.secho(f"[simvue] Run {self._name} created", bold=True, fg="green")
click.secho(
f"[simvue] Run {self._name} created",
bold=self._term_color,
fg="green" if self._term_color else None,
)
click.secho(
f"[simvue] Monitor in the UI at {self._url}/dashboard/runs/run/{self._id}",
bold=True,
fg="green",
bold=self._term_color,
fg="green" if self._term_color else None,
)

return True
Expand Down Expand Up @@ -1205,9 +1214,9 @@ def save_file(

if not file_size:
click.secho(
"WARNING: saving zero-sized files not currently supported",
bold=True,
fg="yellow",
"[simvue] WARNING: saving zero-sized files not currently supported",
bold=self._term_color,
fg="yellow" if self._term_color else None,
)
return True

Expand Down Expand Up @@ -1393,10 +1402,10 @@ def close(self) -> bool:
if _error_msg:
_error_msg = f":\n{_error_msg}"
click.secho(
"Simvue process executor terminated with non-zero exit status "
"[simvue] Process executor terminated with non-zero exit status "
f"{_non_zero}{_error_msg}",
fg="red",
bold=True,
fg="red" if self._term_color else None,
bold=self._term_color,
)
sys.exit(_non_zero)

Expand Down
3 changes: 2 additions & 1 deletion tests/refactor/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ def setup_test_run(run: sv_run.Run, create_objects: bool, request: pytest.Fixtur
tags=TEST_DATA["tags"],
folder=TEST_DATA["folder"],
visibility="tenant" if os.environ.get("CI") else None,
retention_period="1 hour"
retention_period="1 hour",
no_color=True
)
run._dispatcher._max_buffer_size = MAX_BUFFER_SIZE

Expand Down
Loading