Skip to content

Commit

Permalink
feat(cli): optionally hide version splash (#3329)
Browse files Browse the repository at this point in the history
* 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 <mrdiverlp@gmail.com>
  • Loading branch information
jeertmans and MrDiver authored Dec 10, 2023
1 parent 03f9d4b commit 018e4a3
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
21 changes: 17 additions & 4 deletions manim/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import sys

import click
import cloup

from . import __version__, cli_ctx_settings, console
Expand All @@ -14,12 +15,15 @@
from .constants import EPILOG


def exit_early(ctx, param, value):
def show_splash(ctx, param, value):
if value:
sys.exit()
console.print(f"Manim Community [green]v{__version__}[/green]\n")


console.print(f"Manim Community [green]v{__version__}[/green]\n")
def print_version_and_exit(ctx, param, value):
show_splash(ctx, param, value)
if value:
ctx.exit()


@cloup.group(
Expand All @@ -37,7 +41,16 @@ def exit_early(ctx, param, value):
"--version",
is_flag=True,
help="Show version and exit.",
callback=exit_early,
callback=print_version_and_exit,
is_eager=True,
expose_value=False,
)
@click.option(
"--show-splash/--hide-splash",
is_flag=True,
default=True,
help="Print splash message with version information.",
callback=show_splash,
is_eager=True,
expose_value=False,
)
Expand Down
12 changes: 9 additions & 3 deletions tests/interface/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ def test_manim_cfg_subcommand():
command = ["cfg"]
runner = CliRunner()
result = runner.invoke(main, command, prog_name="manim")
expected_output = """\
expected_output = f"""\
Manim Community v{__version__}
Usage: manim cfg [OPTIONS] COMMAND [ARGS]...
Manages Manim configuration files.
Expand All @@ -50,7 +52,9 @@ def test_manim_plugins_subcommand():
command = ["plugins"]
runner = CliRunner()
result = runner.invoke(main, command, prog_name="manim")
expected_output = """\
expected_output = f"""\
Manim Community v{__version__}
Usage: manim plugins [OPTIONS]
Manages Manim plugins.
Expand Down Expand Up @@ -90,7 +94,9 @@ def test_manim_init_subcommand():
command = ["init"]
runner = CliRunner()
result = runner.invoke(main, command, prog_name="manim")
expected_output = """\
expected_output = f"""\
Manim Community v{__version__}
Usage: manim init [OPTIONS] COMMAND [ARGS]...
Create a new project or insert a new scene.
Expand Down

0 comments on commit 018e4a3

Please sign in to comment.