Skip to content

Commit 4d63757

Browse files
authored
Don't show spinner with verbose output (#160)
The spinner interferes with the extra output when verbose output is enabled (`-v` option).
1 parent 9a1b522 commit 4d63757

File tree

3 files changed

+23
-7
lines changed

3 files changed

+23
-7
lines changed

aiidalab_launch/__main__.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,10 @@ def callback(ctx, param, value): # noqa: U100
9292
"-v",
9393
"--verbose",
9494
count=True,
95-
help="Provide this option to increase the output verbosity of the launcher.",
95+
help=(
96+
"Increase the output verbosity of the launcher. "
97+
"Use '-vv' or '-vvv' for even more verbose output"
98+
),
9699
)
97100
@pass_app_state
98101
def cli(app_state, verbose):

aiidalab_launch/util.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import asyncio
2+
import logging
23
import re
34
import webbrowser
45
from contextlib import contextmanager
@@ -36,18 +37,27 @@
3637

3738
@contextmanager
3839
def spinner(
39-
msg: Optional[str] = None, final: Optional[str] = None, delay: float = 0
40+
msg: Optional[str] = None, final: Optional[str] = "done.", delay: float = 0
4041
) -> Generator[None, None, None]:
4142
"""Display spinner only after an optional initial delay."""
4243

4344
def spin() -> None:
45+
46+
# Don't show spinner if verbose output is enabled
47+
level = logging.getLogger().getEffectiveLevel()
48+
show_spinner = (
49+
True if level == logging.NOTSET or level >= logging.ERROR else False
50+
)
4451
if msg:
45-
click.echo(f"{msg.rstrip()} ", nl=False, err=True)
46-
with click_spinner.spinner(): # type: ignore
52+
newline = not show_spinner
53+
click.echo(f"{msg.rstrip()} ", nl=newline, err=True)
54+
55+
if show_spinner:
56+
with click_spinner.spinner(): # type: ignore
57+
stop.wait()
58+
click.echo(final if (completed.is_set() and msg) else " ", err=True)
59+
else:
4760
stop.wait()
48-
click.echo(
49-
(final or "done.") if (completed.is_set() and msg) else " ", err=True
50-
)
5161

5262
stop = Event()
5363
completed = Event()

tests/test_cli.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,8 @@ def assert_status_down():
214214
assert result.exit_code == 0
215215

216216
# Start instance again (blocking, should be no-op).
217+
# Disabling verbose logging to test the spinner
218+
caplog.set_level(logging.ERROR)
217219
runner: CliRunner = CliRunner()
218220
result: Result = runner.invoke(
219221
cli.cli, ["start", "--no-browser", "--no-pull", "--wait=300"]
@@ -225,6 +227,7 @@ def assert_status_down():
225227
assert get_volume(instance.profile.conda_volume_name())
226228

227229
# Start instance again – should be noop.
230+
caplog.set_level(logging.DEBUG)
228231
result: Result = runner.invoke(
229232
cli.cli, ["start", "--no-browser", "--no-pull", "--wait=300"]
230233
)

0 commit comments

Comments
 (0)