Coverage for src/manimgx/cli/__init__.py: 100%

23 statements  

« prev     ^ index     » next       coverage.py v7.16.1, created at 2026-10-26 05:52 +0000

1"""The ManimGX command line: a scene rendered to video, inspected, presented, 

2and previewed live. 

3 

4 manimgx render scene.py [Scene] [-o video.mp4] the video, a storyboard, layout problems 

5 manimgx inspect scene.py [Scene] [-t 0,2.5,end] timeline, storyboard, layout problems 

6 manimgx present scene.py [Scene] its sections as slides, in the browser 

7 manimgx preview scene.py [Scene] a window playing it, again on each save 

8 

9What a command writes goes to stdout, one line per file, then its report; errors go to stderr. 

10Exit 0 on success, 1 when the scene fails (or `inspect` finds problems), 2 when the command is 

11wrong. Help is plain text when piped (an agent's shell), rich on a terminal. 

12""" 

13 

14import sys 

15 

16from manimgx import _engine 

17 

18# A command that draws starts the GPU before the rest of the command line loads (its modules, 

19# then the scene's file), so that the GPU comes up meanwhile; `--version`, `--help` and 

20# `preview` (its window draws its takes) never bring it up. 

21DRAWING = ("render", "inspect", "present") 

22if sys.argv[1:2] and sys.argv[1] in DRAWING and not {"-h", "--help"} & set(sys.argv): 

23 _engine.start_gpu() 

24 

25from importlib.metadata import version 

26from typing import Annotated 

27 

28import typer 

29 

30from manimgx.cli.export import inspect, present, render 

31from manimgx.cli.preview import preview 

32 

33app = typer.Typer( 

34 name="manimgx", 

35 no_args_is_help=True, 

36 add_completion=False, 

37 rich_markup_mode="rich" if sys.stdout.isatty() else None, 

38 pretty_exceptions_enable=False, 

39 context_settings={"help_option_names": ["-h", "--help"]}, 

40) 

41 

42 

43def _version(shown: bool) -> None: 

44 if shown: 

45 typer.echo(f"manimgx {version('manimgx')}") 

46 raise typer.Exit 

47 

48 

49@app.callback() 

50def manimgx( 

51 _: Annotated[ 

52 bool, 

53 typer.Option( 

54 "--version", 

55 callback=_version, 

56 is_eager=True, 

57 help="Show the version and exit.", 

58 ), 

59 ] = False, 

60) -> None: 

61 """The animation engine for agents: blazingly fast math and 3D videos with Manim's Python API, on a Rust GPU core. 

62 

63 A scene file is Manim CE code: `import manimgx as m`, a class deriving m.Scene, its 

64 `construct`. Work in a loop: 

65 

66 \b 

67 manimgx inspect scene.py timeline, storyboard, layout problems 

68 manimgx inspect scene.py -t 1.5,end inspect specific moments 

69 manimgx render scene.py the video (MP4), with the same report 

70 

71 Files are written beside the scene file; each command prints what it wrote.""" 

72 

73 

74app.command()(render) 

75app.command()(inspect) 

76app.command()(preview) 

77app.command()(present) 

78 

79 

80def main() -> None: 

81 app(prog_name="manimgx")