Skip to content

Commit 0de873c

Browse files
authored
Cleanup __main__.py - remove stray print statements (#1078)
* Cleanup __main__.py - remove stray print statements use rich's print traceback instead fix double printing of version when --version is called Add some tests for the subcommands Signed-off-by: Naveen M K <[email protected]> * Run black * tests: remove importlib_metadata usage
1 parent 9f51ed9 commit 0de873c

File tree

3 files changed

+66
-8
lines changed

3 files changed

+66
-8
lines changed

manim/__main__.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,23 +81,19 @@ def main():
8181
server.start()
8282
server.wait_for_termination()
8383
except ModuleNotFoundError as e:
84-
print("\n\n")
85-
print(
84+
console.print(
8685
"Dependencies for the WebGL render are missing. Run "
8786
"pip install manim[webgl_renderer] to install them."
8887
)
89-
print(e)
90-
print("\n\n")
88+
console.print_exception()
9189
else:
9290
for SceneClass in scene_classes_from_file(input_file):
9391
try:
9492
scene = SceneClass()
9593
scene.render()
9694
open_file_if_needed(scene.renderer.file_writer)
9795
except Exception:
98-
print("\n\n")
99-
traceback.print_exc()
100-
print("\n\n")
96+
console.print_exception()
10197

10298

10399
if __name__ == "__main__":

manim/_config/main_utils.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,6 @@ def parse_args(args: list) -> argparse.Namespace:
111111
elif subcmd == "plugins":
112112
return _parse_args_plugins(args)
113113
elif args[1] == "--version":
114-
print(f"Manim Community v{ __version__ }")
115114
sys.exit()
116115
# elif subcmd == some_other_future_subcmd:
117116
# return _parse_args_some_other_subcmd(args)

tests/test_commands.py

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import subprocess
2+
import sys
3+
4+
from .test_plugins.test_plugins import function_like_plugin
5+
6+
import manim
7+
8+
9+
def call_command(command, cwd=None, env=None):
10+
a = subprocess.run(
11+
command,
12+
stdout=subprocess.PIPE,
13+
stderr=subprocess.PIPE,
14+
check=True,
15+
text=True,
16+
cwd=cwd,
17+
env=env,
18+
)
19+
return a
20+
21+
22+
def test_manim_version_from_command_line():
23+
a = call_command(
24+
[
25+
sys.executable,
26+
"-m",
27+
"manim",
28+
"--version",
29+
]
30+
)
31+
version = manim.__version__
32+
assert version in a.stdout
33+
assert a.stdout.strip() == f"Manim Community v{version}"
34+
35+
36+
def test_manim_cfg_subcommand_no_subcommand():
37+
a = call_command(
38+
[
39+
sys.executable,
40+
"-m",
41+
"manim",
42+
"cfg",
43+
]
44+
)
45+
assert "No subcommand provided; Exiting..." in a.stdout
46+
47+
48+
def test_manim_plugis_subcommand_no_subcommand():
49+
a = call_command(
50+
[
51+
sys.executable,
52+
"-m",
53+
"manim",
54+
"plugins",
55+
]
56+
)
57+
assert "No flag provided; Exiting..." in a.stdout
58+
59+
60+
def test_manim_plugis_subcommand_listing(function_like_plugin):
61+
# Check whether `test_plugin` is in plugins list
62+
a = call_command([sys.executable, "-m", "manim", "plugins", "--list"])
63+
assert "test_plugin" in a.stdout

0 commit comments

Comments
 (0)