Skip to content

armgit / manim

Public Imported from GitHub
0

A community-maintained Python framework for creating mathematical animations.

add the partial_movie_dir as a config option

leotrs4b12fde0259f
diff --git a/manim/config/default.cfg b/manim/config/default.cfg
index 2fff637ae..62e76abab 100644
--- a/manim/config/default.cfg
+++ b/manim/config/default.cfg
@@ -79,6 +79,7 @@ video_dir = {media_dir}/videos/{module_name}/{quality}
images_dir = {media_dir}/images/{module_name}
tex_dir = {media_dir}/Tex
text_dir = {media_dir}/texts
+partial_movie_dir = {video_dir}/partial_movie_files/{scene_name}
# --use_js_renderer
use_js_renderer = False
@@ -132,6 +133,7 @@ images_dir = {media_dir}
text_dir = {media_dir}/temp_files
tex_dir = {media_dir}/temp_files
log_dir = {media_dir}/temp_files
+partial_movie_dir = {media_dir}/partial_movie_files/{scene_name}
# Rich settings
[logger]
diff --git a/manim/config/utils.py b/manim/config/utils.py
index fdc2b9713..812855654 100644
--- a/manim/config/utils.py
+++ b/manim/config/utils.py
@@ -116,6 +116,7 @@ class ManimConfig(MutableMapping):
"max_files_cached",
"media_dir",
"movie_file_extension",
+ "partial_movie_dir",
"pixel_height",
"pixel_width",
"png_mode",
@@ -280,6 +281,7 @@ class ManimConfig(MutableMapping):
"images_dir",
"text_dir",
"tex_dir",
+ "partial_movie_dir",
"input_file",
"output_file",
"png_mode",
@@ -391,7 +393,15 @@ class ManimConfig(MutableMapping):
# Handle --custom_folders
if args.custom_folders:
- for opt in ["media_dir", "video_dir", "images_dir", "text_dir", "tex_dir", "log_dir"]:
+ for opt in [
+ "media_dir",
+ "video_dir",
+ "images_dir",
+ "text_dir",
+ "tex_dir",
+ "log_dir",
+ "partial_movie_dir",
+ ]:
self[opt] = self._parser["custom_folders"].get(opt, raw=True)
# --media_dir overrides the deaful.cfg file
if hasattr(args, "media_dir") and args.media_dir:
@@ -746,6 +756,7 @@ class ManimConfig(MutableMapping):
"log_dir",
"input_file",
"output_file",
+ "partial_movie_dir",
]
if key not in dirs:
raise KeyError('must pass one of '
@@ -758,13 +769,14 @@ class ManimConfig(MutableMapping):
all_args.update(kwargs)
all_args['quality'] = f'{self.pixel_height}p{self.frame_rate}'
- try:
- path = self._d[key].format(**all_args)
- except KeyError as exc:
- raise KeyError(f'{key} {self._d[key]} requires the following '
- + 'keyword arguments: '
- + " ".join(exc.args)
- + f'but quality is {self.quality}') from exc
+ path = self._d[key]
+ while '{' in path:
+ try:
+ path = path.format(**all_args)
+ except KeyError as exc:
+ raise KeyError(f'{key} {self._d[key]} requires the following '
+ + 'keyword arguments: '
+ + " ".join(exc.args)) from exc
return Path(path) if path else None
@@ -804,6 +816,12 @@ class ManimConfig(MutableMapping):
doc="Directory to place tex",
)
+ partial_movie_dir = property(
+ lambda self: self._d["partial_movie_dir"],
+ lambda self, val: self._set_dir("partial_movie_dir", val),
+ doc="Directory to place partial movie files",
+ )
+
custom_folders = property(
lambda self: self._d["custom_folders"],
lambda self, val: self._set_boolean("custom_folders", val),
diff --git a/manim/scene/scene_file_writer.py b/manim/scene/scene_file_writer.py
index 16d4a2813..636dd8814 100644
--- a/manim/scene/scene_file_writer.py
+++ b/manim/scene/scene_file_writer.py
@@ -102,23 +102,13 @@ class SceneFileWriter(object):
add_extension_if_not_present(default_name, GIF_FILE_EXTENSION),
)
- if not config["custom_folders"]:
- self.partial_movie_directory = guarantee_existence(
- os.path.join(
- movie_dir,
- "partial_movie_files",
- default_name,
- )
- )
- else:
- self.partial_movie_directory = guarantee_existence(
- os.path.join(
- config.get_dir("media_dir"),
- "temp_files",
- "partial_movie_files",
- default_name,
- )
+ self.partial_movie_directory = guarantee_existence(
+ config.get_dir(
+ 'partial_movie_dir',
+ scene_name=default_name,
+ module_name=module_name
)
+ )
def add_partial_movie_file(self, hash_animation):
"""Adds a new partial movie file path to scene.partial_movie_files from an hash. This method will compute the path from the hash.