A community-maintained Python framework for creating mathematical animations.
Implements `-q[l|m|h|k]` (#514)
Julian van Doornfa0a82c2261a
diff --git a/docs/source/changelog.rst b/docs/source/changelog.rstindex ce115c644..8da9951c1 100644--- a/docs/source/changelog.rst+++ b/docs/source/changelog.rst@@ -19,8 +19,6 @@ New FeaturesCommand line^^^^^^^^^^^^-#. Add 4k rendering option with the :code:`-k` option-#. High quality rendering has gotten its own short argument (:code:`-e`)#. Output of 'manim --help' has been improved#. Implement logging with the :code:`rich` library and a :code:`logger` object instead of plain ol` prints#. Added a flag :code:`--dry_run`, which doesn’t write any media@@ -33,6 +31,7 @@ Command line#. Added a :code:`--verbose` flag#. You can save the logs to a file by using :code:`--log_to_file`#. Add experimental javascript rendering with :code:`--use_js_renderer`+#. Add :code:`-q/--quality [k|h|m|l]` flag and removed :code:`-m/-l` flags.Config systemdiff --git a/docs/source/tutorials/configuration.rst b/docs/source/tutorials/configuration.rstindex a87ee8dd7..9cfd0822a 100644--- a/docs/source/tutorials/configuration.rst+++ b/docs/source/tutorials/configuration.rst@@ -17,7 +17,7 @@ Usually, manim is ran from the command line by executingThis asks manim to search for a Scene class called :code:`SceneName` inside thefile <file.py> and render it. One can also specify the render quality by using-the flags :code:`-l`, :code:`-m`, :code:`-e`, or :code:`-k`, for low, medium,+the flags :code:`-ql`, :code:`-qm`, :code:`-qh`, or :code:`-qk`, for low, medium,high, and 4k quality, respectively... code-block:: bash@@ -46,89 +46,79 @@ The output looks as follows... testoutput:::options: -ELLIPSIS, +NORMALIZE_WHITESPACE- usage: manim [-h] [-o OUTPUT_FILE] [-p] [-f] [--sound] [--leave_progress_bars]- [-a] [-w] [-s] [-g] [-i] [--disable_caching] [--flush_cache]- [--log_to_file] [-c BACKGROUND_COLOR]- [--background_opacity BACKGROUND_OPACITY] [--media_dir MEDIA_DIR]- [--log_dir LOG_DIR] [--tex_template TEX_TEMPLATE] [--dry_run]- [-t] [-l] [-m] [-e] [-k] [-r RESOLUTION]- [-n FROM_ANIMATION_NUMBER] [--config_file CONFIG_FILE]- [--custom_folders] [-v {DEBUG,INFO,WARNING,ERROR,CRITICAL}]- [--progress_bar True/False]- {cfg} ... file [scene_names [scene_names ...]]-- Animation engine for explanatory math videos-- positional arguments:- {cfg}- file path to file holding the python code for the scene- scene_names Name of the Scene class you want to see-- optional arguments:- -h, --help show this help message and exit- -o OUTPUT_FILE, --output_file OUTPUT_FILE- Specify the name of the output file, if it should be- different from the scene class name- -p, --preview Automatically open the saved file once its done- -f, --show_in_file_browser- Show the output file in the File Browser- --sound Play a success/failure sound- --leave_progress_bars- Leave progress bars displayed in terminal- -a, --write_all Write all the scenes from a file- -w, --write_to_movie Render the scene as a movie file (this is on by- default)- -s, --save_last_frame- Save the last frame only (no movie file is generated)- -g, --save_pngs Save each frame as a png- -i, --save_as_gif Save the video as gif- --disable_caching Disable caching (will generate partial-movie-files- anyway)- --flush_cache Remove all cached partial-movie-files- --log_to_file Log terminal output to file- -c BACKGROUND_COLOR, --background_color BACKGROUND_COLOR- Specify background color- --background_opacity BACKGROUND_OPACITY- Specify background opacity- --media_dir MEDIA_DIR- Directory to store media (including video files)- --log_dir LOG_DIR Directory to store log files- --tex_template TEX_TEMPLATE- Specify a custom TeX template file- --dry_run Do a dry run (render scenes but generate no output- files)- -t, --transparent Render a scene with an alpha channel- -l, --low_quality Render at low quality- -m, --medium_quality Render at medium quality- -e, --high_quality Render at high quality- -k, --fourk_quality Render at 4K quality- -r RESOLUTION, --resolution RESOLUTION- Resolution, passed as "height,width". Overrides the- -l, -m, -e, and -k flags, if present- -n FROM_ANIMATION_NUMBER, --from_animation_number FROM_ANIMATION_NUMBER- 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 the- rendering at the second value- --config_file CONFIG_FILE- Specify the configuration file- --custom_folders Use the folders defined in the [custom_folders]- section of the config file to define the output folder- structure- -v {DEBUG,INFO,WARNING,ERROR,CRITICAL}, --verbosity {DEBUG,INFO,WARNING,ERROR,CRITICAL}- Verbosity level. Also changes the ffmpeg log level- unless the latter is specified in the config- --progress_bar True/False- Display the progress bar-- Made with <3 by the manim community devs+ usage: manim [-h] [-o OUTPUT_FILE] [-p] [-f] [--sound] [--leave_progress_bars] [-a] [-w] [-s] [-g] [-i] [--disable_caching] [--flush_cache] [--log_to_file] [-c BACKGROUND_COLOR]+ [--background_opacity BACKGROUND_OPACITY] [--media_dir MEDIA_DIR] [--log_dir LOG_DIR] [--tex_template TEX_TEMPLATE] [--dry_run] [-t] [-q {k,h,m,l}] [--low_quality] [--medium_quality]+ [--high_quality] [--fourk_quality] [-r RESOLUTION] [-n FROM_ANIMATION_NUMBER] [--use_js_renderer] [--js_renderer_path JS_RENDERER_PATH] [--config_file CONFIG_FILE] [--custom_folders]+ [-v {DEBUG,INFO,WARNING,ERROR,CRITICAL}] [--progress_bar True/False]+ {cfg} ... file [scene_names [scene_names ...]]++Animation engine for explanatory math videos++positional arguments:+ {cfg}+ file path to file holding the python code for the scene+ scene_names Name of the Scene class you want to see++optional arguments:+ -h, --help show this help message and exit+ -o OUTPUT_FILE, --output_file OUTPUT_FILE+ Specify the name of the output file, if it should be different from the scene class name+ -p, --preview Automatically open the saved file once its done+ -f, --show_in_file_browser+ Show the output file in the File Browser+ --sound Play a success/failure sound+ --leave_progress_bars+ Leave progress bars displayed in terminal+ -a, --write_all Write all the scenes from a file+ -w, --write_to_movie Render the scene as a movie file (this is on by default)+ -s, --save_last_frame+ Save the last frame only (no movie file is generated)+ -g, --save_pngs Save each frame as a png+ -i, --save_as_gif Save the video as gif+ --disable_caching Disable caching (will generate partial-movie-files anyway)+ --flush_cache Remove all cached partial-movie-files+ --log_to_file Log terminal output to file+ -c BACKGROUND_COLOR, --background_color BACKGROUND_COLOR+ Specify background color+ --background_opacity BACKGROUND_OPACITY+ Specify background opacity+ --media_dir MEDIA_DIR+ Directory to store media (including video files)+ --log_dir LOG_DIR Directory to store log files+ --tex_template TEX_TEMPLATE+ Specify a custom TeX template file+ --dry_run Do a dry run (render scenes but generate no output files)+ -t, --transparent Render a scene with an alpha channel+ -q {k,h,m,l}, --quality {k,h,m,l}+ Render at specific quality, short form of the --*_quality flags+ --low_quality Render at low quality+ --medium_quality Render at medium quality+ --high_quality Render at high quality+ --fourk_quality Render at 4K quality+ -r RESOLUTION, --resolution RESOLUTION+ Resolution, passed as "height,width". Overrides any quality flags, if present+ -n FROM_ANIMATION_NUMBER, --from_animation_number FROM_ANIMATION_NUMBER+ 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 the rendering at the second+ value+ --use_js_renderer Render animations using the javascript frontend+ --js_renderer_path JS_RENDERER_PATH+ Path to the javascript frontend+ --config_file CONFIG_FILE+ Specify the configuration file+ --custom_folders Use the folders defined in the [custom_folders] section of the config file to define the output folder structure+ -v {DEBUG,INFO,WARNING,ERROR,CRITICAL}, --verbosity {DEBUG,INFO,WARNING,ERROR,CRITICAL}+ Verbosity level. Also changes the ffmpeg log level unless the latter is specified in the config+ --progress_bar True/False+ Display the progress bar++Made with <3 by the manim community devsFor example, to render a scene in high quality, but only output the last frameof the scene instead of the whole video, you can execute.. code-block:: bash- $ manim <file.py> SceneName -es+ $ manim <file.py> SceneName -sqhThe following example specifies the output file name (with the :code:`-o`flag), renders only the first ten animations (:code:`-n` flag) with a whitediff --git a/manim/config/config.py b/manim/config/config.pyindex eb80a31fb..f3c95bcc5 100644--- a/manim/config/config.py+++ b/manim/config/config.py@@ -16,7 +16,12 @@ from contextlib import contextmanagerimport colourfrom .. import constants-from .config_utils import _run_config, _init_dirs, _from_command_line+from .config_utils import (+ _determine_quality,+ _run_config,+ _init_dirs,+ _from_command_line,+)from .logger import set_rich_logger, set_file_logger, loggerfrom ..utils.tex import TexTemplate, TexTemplateFromFile@@ -80,13 +85,11 @@ def _parse_config(config_parser, args):# Handle the *_quality flags. These determine the section to read# and are stored in 'camera_config'. Note the highest resolution# passed as argument will be used.- for flag in ["fourk_quality", "high_quality", "medium_quality", "low_quality"]:- if getattr(args, flag):- section = config_parser[flag]- break- else:- section = config_parser["CLI"]- config = {opt: section.getint(opt) for opt in config_parser[flag]}+ quality = _determine_quality(args)+ section = config_parser[quality if quality != "production" else "CLI"]++ # Loop over low quality for the keys, could be any quality really+ config = {opt: section.getint(opt) for opt in config_parser["low_quality"]}config["default_pixel_height"] = default.getint("pixel_height")config["default_pixel_width"] = default.getint("pixel_width")@@ -152,6 +155,8 @@ def _parse_config(config_parser, args):args, config_parser, file_writer_config, successfully_read_files = _run_config()logger.setLevel(file_writer_config["verbosity"])+set_rich_logger(config_parser["logger"], file_writer_config["verbosity"])+if _from_command_line():logger.debug(f"Read configuration files: {[os.path.abspath(cfgfile) for cfgfile in successfully_read_files]}"@@ -163,8 +168,6 @@ if config["use_js_renderer"]:file_writer_config["disable_caching"] = Truecamera_config = config-# Set the different loggers-set_rich_logger(config_parser["logger"], file_writer_config["verbosity"])if file_writer_config["log_to_file"]:# IMPORTANT note about file name : The log file name will be the scene_name get from the args (contained in file_writer_config). So it can differ from the real name of the scene.log_file_path = os.path.join(diff --git a/manim/config/config_utils.py b/manim/config/config_utils.pyindex b85efa55e..820d2775e 100644--- a/manim/config/config_utils.py+++ b/manim/config/config_utils.py@@ -17,13 +17,11 @@ __all__ = [import argparseimport configparser+import loggingimport osimport sys-import colour-from .. import constants-from ..utils.tex import TexTemplate, TexTemplateFromFiledef _parse_file_writer_config(config_parser, args):@@ -349,36 +347,60 @@ def _parse_cli(arg_list, input=True):# The following are mutually exclusive and each overrides# FRAME_RATE, PIXEL_HEIGHT, and PIXEL_WIDTH,parser.add_argument(- "-l",+ "-q",+ "--quality",+ choices=constants.QUALITIES.values(),+ help="Render at specific quality, short form of the --*_quality flags",+ )+ parser.add_argument("--low_quality",action="store_true",help="Render at low quality",)parser.add_argument(- "-m","--medium_quality",action="store_true",help="Render at medium quality",)parser.add_argument(- "-e","--high_quality",action="store_true",help="Render at high quality",)parser.add_argument(- "-k","--fourk_quality",action="store_true",help="Render at 4K quality",)+ # Deprecated quality flags+ parser.add_argument(+ "-l",+ action="store_true",+ help="DEPRECATED: USE -ql or --quality l",+ )+ parser.add_argument(+ "-m",+ action="store_true",+ help="DEPRECATED: USE -qm or --quality m",+ )+ parser.add_argument(+ "-e",+ action="store_true",+ help="DEPRECATED: USE -qh or --quality h",+ )+ parser.add_argument(+ "-k",+ action="store_true",+ help="DEPRECATED: USE -qk or --quality k",+ )+# This overrides any of the aboveparser.add_argument("-r","--resolution",help='Resolution, passed as "height,width". '- "Overrides the -l, -m, -e, and -k flags, if present",+ "Overrides any quality flags, if present",)# This sets FROM_ANIMATION_NUMBER and UPTO_ANIMATION_NUMBER@@ -624,3 +646,27 @@ def _init_cfg_subcmd(subparsers):cfg_export_parser.add_argument("--dir", default=os.getcwd())return cfg_related+++def _determine_quality(args):+ old_qualities = {+ "k": "fourk_quality",+ "e": "high_quality",+ "m": "medium_quality",+ "l": "low_quality",+ }++ for quality in constants.QUALITIES.keys():+ if getattr(args, quality) or (+ hasattr(args, "quality") and args.quality == constants.QUALITIES[quality]+ ):+ return quality++ for quality in old_qualities.keys():+ if getattr(args, quality):+ logging.getLogger("manim").warning(+ f"Option -{quality} is deprecated please use the --quality/-q flag."+ )+ return old_qualities[quality]++ return "production"diff --git a/manim/constants.py b/manim/constants.pyindex 8fe4c8cea..75d4d70f0 100644--- a/manim/constants.py+++ b/manim/constants.py@@ -126,3 +126,11 @@ JS_RENDERER_INFO = ("you can either start it prior to running Manim or specify the path to the ""executable with the --js_renderer_path flag.")++# Video qualities+QUALITIES = {+ "fourk_quality": "k",+ "high_quality": "h",+ "medium_quality": "m",+ "low_quality": "l",+}diff --git a/tests/test_cli_flags.py b/tests/test_cli_flags.pynew file mode 100644index 000000000..4c45471b2--- /dev/null+++ b/tests/test_cli_flags.py@@ -0,0 +1,44 @@+from manim import constants+from manim.config.config_utils import _determine_quality, _parse_cli+++def test_quality_flags():+ # Assert that quality is None when not specifying it+ parsed = _parse_cli([], False)++ assert not parsed.quality++ for quality in constants.QUALITIES.keys():+ # Assert that quality is properly set when using -q*+ arguments = f"-q{constants.QUALITIES[quality]}".split()+ parsed = _parse_cli(arguments, False)++ assert parsed.quality == constants.QUALITIES[quality]+ assert quality == _determine_quality(parsed)++ # Assert that quality is properly set when using -q *+ arguments = f"-q {constants.QUALITIES[quality]}".split()+ parsed = _parse_cli(arguments, False)++ assert parsed.quality == constants.QUALITIES[quality]+ assert quality == _determine_quality(parsed)++ # Assert that quality is properly set when using --quality *+ arguments = f"--quality {constants.QUALITIES[quality]}".split()+ parsed = _parse_cli(arguments, False)++ assert parsed.quality == constants.QUALITIES[quality]+ assert quality == _determine_quality(parsed)++ # Assert that quality is properly set when using -*_quality+ arguments = f"--{quality}".split()+ parsed = _parse_cli(arguments, False)++ assert getattr(parsed, quality)+ assert quality == _determine_quality(parsed)++ # Assert that *_quality is False when not specifying it+ parsed = _parse_cli([], False)++ assert not getattr(parsed, quality)+ assert "production" == _determine_quality(parsed)diff --git a/tests/test_logging/test_logging.py b/tests/test_logging/test_logging.pyindex a180c7315..f9fdaaf2a 100644--- a/tests/test_logging/test_logging.py+++ b/tests/test_logging/test_logging.py@@ -19,7 +19,7 @@ def test_logging_to_file(tmp_path, python_version):"manim",path_basic_scene,"SquareToCircle",- "-l",+ "-ql","--log_to_file","-v","DEBUG",diff --git a/tests/test_scene_rendering/test_caching_relalted.py b/tests/test_scene_rendering/test_caching_relalted.pyindex 48080f4c1..629917332 100644--- a/tests/test_scene_rendering/test_caching_relalted.py+++ b/tests/test_scene_rendering/test_caching_relalted.py@@ -20,7 +20,7 @@ def test_wait_skip(tmp_path, manim_cfg_file, simple_scenes_path):"manim",simple_scenes_path,scene_name,- "-l",+ "-ql","--media_dir",str(tmp_path),"-n",@@ -43,7 +43,7 @@ def test_play_skip(tmp_path, manim_cfg_file, simple_scenes_path):"manim",simple_scenes_path,scene_name,- "-l",+ "-ql","--media_dir",str(tmp_path),"-n",diff --git a/tests/test_scene_rendering/test_cli_flags.py b/tests/test_scene_rendering/test_cli_flags.pyindex 525a6fbe7..aa815223a 100644--- a/tests/test_scene_rendering/test_cli_flags.py+++ b/tests/test_scene_rendering/test_cli_flags.py@@ -1,9 +1,5 @@-import osimport pytest-import subprocess-from manim import file_writer_config-from ..utils.commands import capturefrom ..utils.video_tester import *@@ -38,7 +34,7 @@ def test_basic_scene_l_flag(tmp_path, manim_cfg_file, simple_scenes_path):"manim",simple_scenes_path,scene_name,- "-l",+ "-ql","--media_dir",str(tmp_path),]