Skip to content

armgit / manim

Public Imported from GitHub
0

A community-maintained Python framework for creating mathematical animations.

add the --custom_folders flag, for a simple output folder structure

leotrse0c7a6ca8f46
diff --git a/manim/default.cfg b/manim/default.cfg
index a8361d350..beb4e47c2 100644
--- a/manim/default.cfg
+++ b/manim/default.cfg
@@ -70,21 +70,14 @@ upto_animation_number = -1
# The following are meant to be paths relative to the point of execution.
# Set them at the CLI with the corresponding flag, or set their default
# values here.
-# --media_dir
+
+# --media_dir. Note that video files will be put in a folder below media_dir,
+# as well as Tex and texts.
media_dir = ./media
# --log_dir
log_dir = %(media_dir)s/logs
-# # --video_dir
-# video_dir = %(MEDIA_DIR)s/videos
-
-# # --tex_dir
-# tex_dir = %(MEDIA_DIR)s/Tex
-
-# # --text_dir
-# text_dir = %(MEDIA_DIR)s/texts
-
# If the -t (--transparent) flag is used, these will be replaced with the
# values specified in the [TRANSPARENT] section later in this file.
png_mode = RGB
@@ -156,6 +149,16 @@ streaming_console_banner = Manim is now running in streaming mode.
>>> c = Circle()
>>> manim.play(ShowCreation(c))
+# Overrides the default output folders, NOT the output file names. Note that
+# if the custom_folders flag is present, the Tex and text files will not be put
+# under media_dir, as is the default.
+[custom_folders]
+media_dir = videos
+video_dir = %(media_dir)s
+text_dir = %(media_dir)s/temp_files
+tex_dir = %(media_dir)s/temp_files
+
+# Rich settings
[logger]
logging_keyword = bold yellow
logging_level_notset = dim
diff --git a/manim/scene/scene_file_writer.py b/manim/scene/scene_file_writer.py
index 9d33f37cd..6109e3c71 100644
--- a/manim/scene/scene_file_writer.py
+++ b/manim/scene/scene_file_writer.py
@@ -65,13 +65,18 @@ class SceneFileWriter(object):
if file_writer_config["write_to_movie"]:
if file_writer_config["video_dir"]:
- movie_dir = guarantee_existence(
- os.path.join(
- file_writer_config["video_dir"],
- module_directory,
- self.get_resolution_directory(),
+ if not file_writer_config["custom_folders"]:
+ movie_dir = guarantee_existence(
+ os.path.join(
+ file_writer_config["video_dir"],
+ module_directory,
+ self.get_resolution_directory(),
+ )
+ )
+ else:
+ movie_dir = guarantee_existence(
+ os.path.join(file_writer_config["video_dir"])
)
- )
self.movie_file_path = os.path.join(
movie_dir,
add_extension_if_not_present(
diff --git a/manim/utils/config_utils.py b/manim/utils/config_utils.py
index 0248d4cca..b92c6e4a2 100644
--- a/manim/utils/config_utils.py
+++ b/manim/utils/config_utils.py
@@ -74,6 +74,14 @@ def _parse_file_writer_config(config_parser, args):
for name in dir_names:
fw_config[name] = os.path.join(fw_config["media_dir"], dir_names[name])
+ # the --custom_folders flag overrides the default folder structure with the
+ # custom folders defined in the [custom_folders] section of the config file
+ fw_config["custom_folders"] = args.custom_folders
+ if fw_config["custom_folders"]:
+ fw_config["media_dir"] = config_parser["custom_folders"].get("media_dir")
+ for opt in ["video_dir", "tex_dir", "text_dir"]:
+ fw_config[opt] = config_parser["custom_folders"].get(opt)
+
# Handle the -s (--save_last_frame) flag: invalidate the -w flag
# At this point the save_last_frame option has already been set by
# both CLI and the cfg file, so read the config dict directly
@@ -358,6 +366,13 @@ def _parse_cli(arg_list, input=True):
"--config_file", help="Specify the configuration file",
)
+ # Specify whether to use the custom folders
+ parser.add_argument(
+ "--custom_folders", action="store_true",
+ help="Use the folders defined in the [custom_folders] "
+ "section of the config file to define the output folder structure",
+ )
+
# Specify the verbosity
parser.add_argument(
"-v",
diff --git a/tests/test_cli/write_cfg_sbcmd_input.txt b/tests/test_cli/write_cfg_sbcmd_input.txt
index 1f449281a..98809ff1f 100644
--- a/tests/test_cli/write_cfg_sbcmd_input.txt
+++ b/tests/test_cli/write_cfg_sbcmd_input.txt
@@ -62,6 +62,10 @@ False
+
+
+
+