From 60718bf8d3b7de323fc97516ec2060ebd9fc9834 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9rome=20Eertmans?= Date: Sat, 12 Aug 2023 10:29:30 +0200 Subject: [PATCH 1/3] 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 --- manim/__main__.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/manim/__main__.py b/manim/__main__.py index c90d24bfac..8b1a0249ba 100644 --- a/manim/__main__.py +++ b/manim/__main__.py @@ -21,7 +21,9 @@ def exit_early(ctx, param, value): sys.exit() -console.print(f"Manim Community [green]v{__version__}[/green]\n") +def show_splash(ctx, param, value): + if value: + console.print(f"Manim Community [green]v{__version__}[/green]\n") @cloup.group( @@ -43,6 +45,15 @@ def exit_early(ctx, param, value): 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, +) @click.pass_context def main(ctx): """The entry point for manim.""" From 44a45c391b5abb309b9aadb8823475173cfecbd8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9rome=20Eertmans?= Date: Wed, 16 Aug 2023 17:12:52 +0200 Subject: [PATCH 2/3] chore(tests): make tests pass --- manim/__main__.py | 13 ++++++------- tests/interface/test_commands.py | 16 ++++++++++++---- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/manim/__main__.py b/manim/__main__.py index 8b1a0249ba..019d7a9cbb 100644 --- a/manim/__main__.py +++ b/manim/__main__.py @@ -1,7 +1,5 @@ from __future__ import annotations -import sys - import click import cloup @@ -16,14 +14,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") -def show_splash(ctx, param, value): +def print_version_and_exit(ctx, param, value): + show_splash(ctx, param, value) if value: - console.print(f"Manim Community [green]v{__version__}[/green]\n") + ctx.exit() @cloup.group( @@ -41,7 +40,7 @@ def show_splash(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, ) diff --git a/tests/interface/test_commands.py b/tests/interface/test_commands.py index 995daf2c37..30c3622a37 100644 --- a/tests/interface/test_commands.py +++ b/tests/interface/test_commands.py @@ -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. @@ -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. @@ -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. @@ -141,7 +147,9 @@ def test_manim_new_command(): command = ["new"] runner = CliRunner() result = runner.invoke(main, command, prog_name="manim") - expected_output = """\ + expected_output = f"""\ +Manim Community v{__version__} + Usage: manim new [OPTIONS] COMMAND [ARGS]... (DEPRECATED) Create a new project or insert a new scene. From 9a71deeb13c0457a23d0a5c8d09dd40842fd4b2c Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sun, 10 Dec 2023 22:14:47 +0000 Subject: [PATCH 3/3] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- manim/__main__.py | 3 ++- tests/interface/test_commands.py | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/manim/__main__.py b/manim/__main__.py index 078a031d1b..c11ca88450 100644 --- a/manim/__main__.py +++ b/manim/__main__.py @@ -1,7 +1,8 @@ from __future__ import annotations -import click import sys + +import click import cloup from . import __version__, cli_ctx_settings, console diff --git a/tests/interface/test_commands.py b/tests/interface/test_commands.py index fc6cca22a4..fce3efde82 100644 --- a/tests/interface/test_commands.py +++ b/tests/interface/test_commands.py @@ -140,4 +140,4 @@ def test_manim_init_scene(tmp_path): ) assert (Path(tmp_dir) / "main.py").exists() file_content = (Path(tmp_dir) / "main.py").read_text() - assert "DefaultFileTestScene(Scene):" in file_content \ No newline at end of file + assert "DefaultFileTestScene(Scene):" in file_content