Skip to content

Commit 018e4a3

Browse files
jeertmansMrDiver
andauthored
feat(cli): optionally hide version splash (#3329)
* feat(cli): optionally hide version splash As discussed in #3326, this PR proposes a new optional flag to hide the version splash when manim command in launched. Additionally, the splash print is now inly executed when the CLI is executed, not on module import. After looking at the current documentation, it does not seem to change anything. I only saw that you documented a version splash for when the CLI is used, but not when the module is imported. So removing it should not break the api docs. In the future, users can still have version information with `import manim; print(manim.__version__)`. Closes #3326 * chore(tests): make tests pass --------- Co-authored-by: Tristan Schulz <[email protected]>
1 parent 03f9d4b commit 018e4a3

File tree

2 files changed

+26
-7
lines changed

2 files changed

+26
-7
lines changed

manim/__main__.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import sys
44

5+
import click
56
import cloup
67

78
from . import __version__, cli_ctx_settings, console
@@ -14,12 +15,15 @@
1415
from .constants import EPILOG
1516

1617

17-
def exit_early(ctx, param, value):
18+
def show_splash(ctx, param, value):
1819
if value:
19-
sys.exit()
20+
console.print(f"Manim Community [green]v{__version__}[/green]\n")
2021

2122

22-
console.print(f"Manim Community [green]v{__version__}[/green]\n")
23+
def print_version_and_exit(ctx, param, value):
24+
show_splash(ctx, param, value)
25+
if value:
26+
ctx.exit()
2327

2428

2529
@cloup.group(
@@ -37,7 +41,16 @@ def exit_early(ctx, param, value):
3741
"--version",
3842
is_flag=True,
3943
help="Show version and exit.",
40-
callback=exit_early,
44+
callback=print_version_and_exit,
45+
is_eager=True,
46+
expose_value=False,
47+
)
48+
@click.option(
49+
"--show-splash/--hide-splash",
50+
is_flag=True,
51+
default=True,
52+
help="Print splash message with version information.",
53+
callback=show_splash,
4154
is_eager=True,
4255
expose_value=False,
4356
)

tests/interface/test_commands.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ def test_manim_cfg_subcommand():
2828
command = ["cfg"]
2929
runner = CliRunner()
3030
result = runner.invoke(main, command, prog_name="manim")
31-
expected_output = """\
31+
expected_output = f"""\
32+
Manim Community v{__version__}
33+
3234
Usage: manim cfg [OPTIONS] COMMAND [ARGS]...
3335
3436
Manages Manim configuration files.
@@ -50,7 +52,9 @@ def test_manim_plugins_subcommand():
5052
command = ["plugins"]
5153
runner = CliRunner()
5254
result = runner.invoke(main, command, prog_name="manim")
53-
expected_output = """\
55+
expected_output = f"""\
56+
Manim Community v{__version__}
57+
5458
Usage: manim plugins [OPTIONS]
5559
5660
Manages Manim plugins.
@@ -90,7 +94,9 @@ def test_manim_init_subcommand():
9094
command = ["init"]
9195
runner = CliRunner()
9296
result = runner.invoke(main, command, prog_name="manim")
93-
expected_output = """\
97+
expected_output = f"""\
98+
Manim Community v{__version__}
99+
94100
Usage: manim init [OPTIONS] COMMAND [ARGS]...
95101
96102
Create a new project or insert a new scene.

0 commit comments

Comments
 (0)