Skip to content

Commit a87bb28

Browse files
jsonvillanuevanaveen521kkbehackljanluke
authored
Refactored the Command Line Interface to use Click + Cloup instead of Argparse (#1013)
* Added click dependency and command structure * Refactored code for separation of concerns * Shortened plugins command to plugin, added render options * first draft for render -h * First successful render using click * Cleaned main * Moved flush_cache to option, ran black * Removed argparse logic, scattered print statements * corrected tests, all passing * merge upstream * fixed test with click's clirunner * Fixed doctest configuration.rst * Temporarily add in main_utils * Removed main_utils.parse_args, used ManimConfig.digest_args * fixed progress bar * Fix jupyter * black * Fixed incorrectly merged merge conflict * updated README command.png image * updated configuration.rst expected output * Fixed test_plugins and config_file expected type * Refixed the jupyter fix * Apply 3/5 suggestions Remove stray print Improve readability of test code Added module docs for the subcommands * Updated `main` to `manim` for tests * Forced `file` positional argument to be Path type * Fixed main -> manim * Added libpango to linux dependency * Updated poetry.lock * Changed configuration.rst test * Fixed test_a_flag test minor space issue added media_width to configuration.rst * Fixed fps flag in Cairo rendering * Fixed more outdated rst in sphinx docs Removed default for fps option, always overwrote quality Fixed doctest control_data * Fixed more incorrect rst orderings * Update tests/test_commands.py Co-authored-by: Naveen M K <[email protected]> * Added suggestions * Removed unused imports * Reverted entry point back to main * Update manim/_config/default.cfg Co-authored-by: Benjamin Hackl <[email protected]> * Adjusted ipython_magic's call to the entry_point * Converted frame_rate to int if integer * run black * Fixed doctest * Fixed issue with command name from CliRunner * Fixed multiple video windows opening from upstream merge * to black or not to black * Added deprecation warning to render subcommand * warning instead of warn * Applied Naveen's suggestions * Made `manim render` show the help page * Update manim/cli/render/commands.py Co-authored-by: Naveen M K <[email protected]> * Update manim/cli/cfg/commands.py Co-authored-by: Naveen M K <[email protected]> * Update manim/cli/cfg/commands.py Co-authored-by: Naveen M K <[email protected]> * Update manim/cli/plugins/commands.py Co-authored-by: Naveen M K <[email protected]> * Addressed some style changes * add back in write_to_movie temporarily for OpenGL support * Removed sound flag, deprecated use_opengl_renderer, added renderer option * revert webgl_renderer_path removal * Fixed cfg export Fixed readme usage of CLI * Flake8/black * Fixed bug in setting renderer choice * Removed log message due to default option Removed default option of background color Fixed write_to_movie flag default * Fix log_to_file tests * Make '-c' option for config_file, not background_color * print colored version always * Remove -v = --version shorthand, conflicts with verbosity * Use subprocess.run instead of Click's CliRunner for stdout * Refactor cli/render to use Cloup instead of click-option-group 1) There's a new file for each option group 2) render is now a cloup.Command, not a Group Fixed issue when an animation is cached, manim can't merge the partial movie files. (#1192) * fixed issue * fixed tests * Update manim/renderer/cairo_renderer.py Co-authored-by: Darylgolden <[email protected]> * added tests * imrpoved test * fixed logic * added new test * check if the file has been outputed * added test when caching is enabled * fixed tests on windows * black * Update manim/renderer/cairo_renderer.py Co-authored-by: Naveen M K <[email protected]> * Update tests/assert_utils.py Co-authored-by: Naveen M K <[email protected]> Co-authored-by: KingWampy <[email protected]> Co-authored-by: Darylgolden <[email protected]> Co-authored-by: Naveen M K <[email protected]> Added :ref_methods: to the manim directive (#1209) * fix manim_directive for methods * added ref_methods to Angle example * black * added new ref_methods references * sort out ref_functions vs ref_methods in examples.rst Co-authored-by: Jason Villanueva <[email protected]> Co-authored-by: Benjamin Hackl <[email protected]> Fixed issue when an animation is cached, manim can't merge the partial movie files. (#1192) * fixed issue * fixed tests * Update manim/renderer/cairo_renderer.py Co-authored-by: Darylgolden <[email protected]> * added tests * imrpoved test * fixed logic * added new test * check if the file has been outputed * added test when caching is enabled * fixed tests on windows * black * Update manim/renderer/cairo_renderer.py Co-authored-by: Naveen M K <[email protected]> * Update tests/assert_utils.py Co-authored-by: Naveen M K <[email protected]> Co-authored-by: KingWampy <[email protected]> Co-authored-by: Darylgolden <[email protected]> Co-authored-by: Naveen M K <[email protected]> Added :ref_methods: to the manim directive (#1209) * fix manim_directive for methods * added ref_methods to Angle example * black * added new ref_methods references * sort out ref_functions vs ref_methods in examples.rst Co-authored-by: Jason Villanueva <[email protected]> Co-authored-by: Benjamin Hackl <[email protected]> Fixed unnecessary args dict * Fixed bug that changed caching hashing result * Revert doctest logic for fps filename output Co-authored-by: Naveen M K <[email protected]> Co-authored-by: Benjamin Hackl <[email protected]> Co-authored-by: Gianluca Gippetto <[email protected]>
1 parent f51133b commit a87bb28

39 files changed

+4011
-4176
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ class SquareToCircle(Scene):
7373
In order to view the output of this scene, save the code in a file called `example.py`. Then, run the following in a terminal window:
7474

7575
```sh
76-
manim example.py SquareToCircle -p -ql
76+
manim -p -ql example.py SquareToCircle
7777
```
7878

7979
You should see your native video player program pop up and play a simple scene in which a square is transformed into a circle. You may find some more simple examples within this

docs/source/_static/command.png

-8.17 KB
Loading

docs/source/installation/plugins.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,15 @@ your available plugins, see the following help output:
3939
.. code-block:: bash
4040
4141
manim plugins -h
42-
usage: manim plugins -h -l
42+
Usage: manim plugins [OPTIONS]
4343
44-
Utility command for managing plugins
44+
Manages Manim plugins.
4545
46-
optional arguments:
47-
-h, --help show this help message and exit
48-
-l, --list Lists all available plugins
46+
Options:
47+
-l, --list List available plugins
48+
-h, --help Show this message and exit.
4949
50-
Made with <3 by the ManimCommunity devs
50+
Made with <3 by Manim Community developers.
5151
5252
You can list plugins as such:
5353

docs/source/tutorials/a_deeper_look.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ At this point, you have just executed the following command.
1414

1515
.. code-block:: bash
1616
17-
$ manim scene.py SquareToCircle -pql
17+
$ manim -pql scene.py SquareToCircle
1818
1919
Let's dissect what just happened step by step. First, this command executes
2020
manim on the file ``scene.py``, which contains our animation code. Further,
@@ -57,7 +57,7 @@ the following command,
5757

5858
.. code-block:: bash
5959
60-
$ manim scene.py SquareToCircle -pqh
60+
$ manim -pqh scene.py SquareToCircle
6161
6262
The ``-ql`` flag (for low quality) has been replaced by the ``-qh`` flag, for
6363
high quality. Manim will take considerably longer to render this file, and it
@@ -144,7 +144,7 @@ When executing the command
144144

145145
.. code-block:: bash
146146
147-
$ manim scene.py SquareToCircle -pql
147+
$ manim -pql scene.py SquareToCircle
148148
149149
it was necessary to specify which ``Scene`` class to render. This is because a
150150
single file can contain more than one ``Scene`` class. If your file contains

docs/source/tutorials/configuration.rst

Lines changed: 49 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ high, and 4k quality, respectively.
9090

9191
.. code-block:: bash
9292
93-
$ manim <file.py> SceneName -ql
93+
$ manim -ql <file.py> SceneName
9494
9595
These flags set the values of the config options ``config.pixel_width``,
9696
``config.pixel_height``, ``config.frame_rate``, and ``config.quality``.
@@ -110,7 +110,7 @@ instead of the whole video, you can execute
110110

111111
.. code-block:: bash
112112
113-
$ manim <file.py> SceneName -sqh
113+
$ manim -sqh <file.py> SceneName
114114
115115
The following example specifies the output file name (with the :code:`-o`
116116
flag), renders only the first ten animations (:code:`-n` flag) with a white
@@ -120,7 +120,7 @@ open the file after it is rendered.
120120

121121
.. code-block:: bash
122122
123-
$ manim <file.py> SceneName -o myscene -i -n 0,10 -c WHITE
123+
$ manim -o myscene -i -n 0,10 -c WHITE <file.py> SceneName
124124
125125
.. tip:: There are many more command line flags that manim accepts. All the
126126
possible flags are shown by executing ``manim -h``. A complete list
@@ -162,7 +162,7 @@ Now, executing the following command
162162

163163
.. code-block:: bash
164164
165-
$ manim <file.py> SceneName -o myscene -i -c WHITE
165+
$ manim -o myscene -i -c WHITE <file.py> SceneName
166166
167167
is equivalent to executing the following command, provided that ``manim.cfg``
168168
is in the same directory as <file.py>,
@@ -187,7 +187,7 @@ file being rendered, and **not** in the directory of execution. For example,
187187

188188
.. code-block:: bash
189189
190-
$ manim <path/to/file.py> SceneName -o myscene -i -c WHITE
190+
$ manim -o myscene -i -c WHITE <path/to/file.py> SceneName
191191
192192
will use the config file found in ``path/to/file.py``, if any. It will **not**
193193
use the config file found in the current working directory, even if it exists.
@@ -260,15 +260,16 @@ using any config files and executing
260260

261261
.. code-block:: bash
262262
263-
manim <file.py> SceneName -o myscene -c WHITE
263+
manim -o myscene -c WHITE <file.py> SceneName
264264
265265
Any command line flags have precedence over any config file. For example,
266-
using the previous two config files and executing :code:`manim <file.py>
267-
SceneName -c RED` is equivalent to not using any config files and executing
266+
using the previous two config files and executing :code:`manim -c RED
267+
<file.py> SceneName` is equivalent to not using any config files and
268+
executing
268269

269270
.. code-block:: bash
270271
271-
manim <file.py> SceneName -o myscene -c RED
272+
manim -o myscene -c RED <file.py> SceneName
272273
273274
There is also a **library-wide** config file that determines manim's default
274275
behavior, and applies to every user of the library. It has the least
@@ -337,114 +338,50 @@ highest precedence, is:
337338
A list of all config options
338339
****************************
339340

340-
.. testcode::
341-
:hide:
342-
343-
from manim._config import ManimConfig
344-
from inspect import getmembers
345-
print(sorted([n for n, _ in getmembers(ManimConfig, lambda v: isinstance(v, property))]))
346-
347-
.. testoutput::
348-
:options: -ELLIPSIS, +NORMALIZE_WHITESPACE
349-
350-
['aspect_ratio', 'assets_dir', 'background_color', 'background_opacity', 'bottom',
351-
'custom_folders', 'disable_caching', 'dry_run', 'ffmpeg_loglevel', 'flush_cache',
352-
'frame_height', 'frame_rate', 'frame_size', 'frame_width', 'frame_x_radius',
353-
'frame_y_radius', 'from_animation_number', 'images_dir', 'input_file',
354-
'leave_progress_bars', 'left_side', 'log_dir', 'log_to_file',
355-
'max_files_cached', 'media_dir', 'media_width', 'movie_file_extension', 'output_file',
356-
'partial_movie_dir', 'pixel_height', 'pixel_width', 'plugins', 'png_mode',
357-
'preview', 'progress_bar', 'quality', 'right_side', 'save_as_gif', 'save_last_frame',
341+
.. code::
342+
343+
['aspect_ratio', 'assets_dir', 'background_color', 'background_opacity',
344+
'bottom', 'custom_folders', 'disable_caching', 'dry_run',
345+
'ffmpeg_loglevel', 'flush_cache', 'frame_height', 'frame_rate',
346+
'frame_size', 'frame_width', 'frame_x_radius', 'frame_y_radius',
347+
'from_animation_number', 'images_dir', 'input_file', 'left_side',
348+
'log_dir', 'log_to_file', 'max_files_cached', 'media_dir', 'media_width',
349+
'movie_file_extension', 'output_file', 'partial_movie_dir',
350+
'pixel_height', 'pixel_width', 'plugins', 'png_mode', 'preview',
351+
'progress_bar', 'quality', 'right_side', 'save_as_gif', 'save_last_frame',
358352
'save_pngs', 'scene_names', 'show_in_file_browser', 'sound', 'tex_dir',
359353
'tex_template', 'tex_template_file', 'text_dir', 'top', 'transparent',
360-
'upto_animation_number', 'use_opengl_renderer', 'use_webgl_renderer', 'verbosity',
361-
'video_dir', 'webgl_renderer_path', 'webgl_updater_fps', 'write_all',
354+
'upto_animation_number', 'use_opengl_renderer', 'use_webgl_renderer',
355+
'verbosity', 'video_dir', 'webgl_renderer_path', 'write_all',
362356
'write_to_movie']
363357
364358
365359
A list of all CLI flags
366360
***********************
367361

368-
.. testcode::
369-
:hide:
370-
371-
import subprocess
372-
import os
373-
is_windows = os.name == 'nt'
374-
result = subprocess.run(['manim', '-h'], shell=is_windows, stdout=subprocess.PIPE)
375-
print(result.stdout.decode('utf-8'))
376-
377-
.. testoutput::
378-
:options: +ELLIPSIS, +NORMALIZE_WHITESPACE
379-
380-
Manim Community v...
381-
usage: manim file [flags] [scene [scene ...]]
382-
manim {cfg,init,plugins} [opts]
383-
384-
Animation engine for explanatory math videos
385-
386-
positional arguments:
387-
file Path to file holding the python code for the scene
388-
scene_names Name of the Scene class you want to see
389-
390-
optional arguments:
391-
-h, --help show this help message and exit
392-
-o OUTPUT_FILE, --output_file OUTPUT_FILE
393-
Specify the name of the output file, if it should be different from the scene class name
394-
-p, --preview Automatically open the saved file once its done
395-
-f, --show_in_file_browser
396-
Show the output file in the File Browser
397-
--sound Play a success/failure sound
398-
--leave_progress_bars
399-
Leave progress bars displayed in terminal
400-
-a, --write_all Write all the scenes from a file
401-
-w, --write_to_movie Render the scene as a movie file (this is on by default)
402-
-s, --save_last_frame
403-
Save the last frame only (no movie file is generated)
404-
-g, --save_pngs Save each frame as a png
405-
-i, --save_as_gif Save the video as gif
406-
--disable_caching Disable caching (will generate partial-movie-files anyway)
407-
--flush_cache Remove all cached partial-movie-files
408-
--log_to_file Log terminal output to file
409-
-c BACKGROUND_COLOR, --background_color BACKGROUND_COLOR
410-
Specify background color
411-
--media_dir MEDIA_DIR
412-
Directory to store media (including video files)
413-
--log_dir LOG_DIR Directory to store log files
414-
--tex_template TEX_TEMPLATE
415-
Specify a custom TeX template file
416-
--dry_run Do a dry run (render scenes but generate no output files)
417-
-t, --transparent Render a scene with an alpha channel
418-
-q {k,p,h,m,l}, --quality {k,p,h,m,l}
419-
Render at specific quality, short form of the --*_quality flags
420-
--low_quality Render at low quality
421-
--medium_quality Render at medium quality
422-
--high_quality Render at high quality
423-
--production_quality Render at default production quality
424-
--fourk_quality Render at 4K quality
425-
-l DEPRECATED: USE -ql or --quality l
426-
-m DEPRECATED: USE -qm or --quality m
427-
-e DEPRECATED: USE -qh or --quality h
428-
-k DEPRECATED: USE -qk or --quality k
429-
-r RESOLUTION, --resolution RESOLUTION
430-
Resolution, passed as "height,width". Overrides the -l, -m, -e, and -k flags, if present
431-
-n FROM_ANIMATION_NUMBER, --from_animation_number FROM_ANIMATION_NUMBER
432-
Start rendering at the specified animation index, instead of the first animation. If you pass in two comma separated values, e.g. '3,6', it will end
433-
the rendering at the second value
434-
--use_opengl_renderer
435-
Render animations using the OpenGL renderer
436-
--use_webgl_renderer Render animations using the WebGL frontend
437-
--webgl_renderer_path WEBGL_RENDERER_PATH
438-
Path to the WebGL frontend
439-
--webgl_updater_fps WEBGL_UPDATER_FPS
440-
Frame rate to use when generating keyframe data for animations that use updaters while using the WebGL frontend
441-
--config_file CONFIG_FILE
442-
Specify the configuration file
443-
--custom_folders Use the folders defined in the [custom_folders] section of the config file to define the output folder structure
444-
-v {DEBUG,INFO,WARNING,ERROR,CRITICAL}, --verbosity {DEBUG,INFO,WARNING,ERROR,CRITICAL}
445-
Verbosity level. Also changes the ffmpeg log level unless the latter is specified in the config
446-
--version Print the current version of Manim you are using
447-
--progress_bar True/False
448-
Display the progress bar
449-
450-
Made with <3 by the ManimCommunity devs
362+
.. code::
363+
364+
manim -h
365+
366+
Usage: manim [OPTIONS] COMMAND [ARGS]...
367+
368+
Animation engine for explanatory math videos
369+
370+
Options:
371+
--version Show the version and exit.
372+
-h, --help Show this message and exit.
373+
374+
Commands:
375+
render* Render SCENE(S) from the input FILE.
376+
cfg Manages Manim configuration files.
377+
plugins Manages Manim plugins.
378+
379+
Made with <3 by Manim Community developers.
380+
381+
Each of the subcommands has their own help page which can be
382+
383+
.. code::
384+
385+
manim render -h
386+
manim cfg -h
387+
manim plugins -h

docs/source/tutorials/quickstart.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ the following command:
5858

5959
.. code-block:: bash
6060
61-
$ manim scene.py SquareToCircle -pql
61+
$ manim -pql scene.py SquareToCircle
6262
6363
After showing some output, manim should render the scene into a .mp4 file,
6464
and open that file with the default movie player application. You should see a
@@ -155,7 +155,7 @@ And render it using the following command:
155155

156156
.. code-block:: bash
157157
158-
$ manim scene.py SquareToCircle -pql
158+
$ manim -pql scene.py SquareToCircle
159159
160160
The output should look as follows.
161161

example_scenes/basic.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
from manim import *
44

55
# To watch one of these scenes, run the following:
6-
# python --quality m manim example_scenes.py SquareToCircle -p
6+
# python --quality m manim -p example_scenes.py SquareToCircle
77
#
88
# Use the flag --quality l for a faster rendering at a lower quality.
99
# Use -s to skip to the end and just save the final frame
1010
# Use the -p to have preview of the animation (or image, if -s was
1111
# used) pop up once done.
1212
# Use -n <number> to skip ahead to the nth animation of a scene.
13-
# Use -r <number> to specify a resolution (for example, -r 1080
13+
# Use -r <number> to specify a resolution (for example, -r 1920,1080
1414
# for a 1920x1080 video)
1515

1616

0 commit comments

Comments
 (0)