Skip to content

Commit d023c76

Browse files
authored
Merge pull request #620 from ManimCommunity/feat-manim-configdict
Replace the global config dict with new class ManimConfig
2 parents 9137126 + e89a96d commit d023c76

32 files changed

+1333
-873
lines changed

docs/source/manim_directive.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -207,18 +207,18 @@ def run(self):
207207
video_dir = os.path.join(media_dir, "videos")
208208
output_file = f"{clsname}-{classnamedict[clsname]}"
209209

210-
file_writer_config_code = [
210+
config_code = [
211211
f'config["frame_rate"] = {frame_rate}',
212212
f'config["pixel_height"] = {pixel_height}',
213213
f'config["pixel_width"] = {pixel_width}',
214-
f'file_writer_config["media_dir"] = r"{media_dir}"',
215-
f'file_writer_config["images_dir"] = r"{images_dir}"',
216-
f'file_writer_config["tex_dir"] = r"{tex_dir}"',
217-
f'file_writer_config["text_dir"] = r"{text_dir}"',
218-
f'file_writer_config["video_dir"] = r"{video_dir}"',
219-
f'file_writer_config["save_last_frame"] = {save_last_frame}',
220-
f'file_writer_config["save_as_gif"] = {save_as_gif}',
221-
f'file_writer_config["output_file"] = r"{output_file}"',
214+
f'config["media_dir"] = r"{media_dir}"',
215+
f'config["images_dir"] = r"{images_dir}"',
216+
f'config["tex_dir"] = r"{tex_dir}"',
217+
f'config["text_dir"] = r"{text_dir}"',
218+
f'config["video_dir"] = r"{video_dir}"',
219+
f'config["save_last_frame"] = {save_last_frame}',
220+
f'config["save_as_gif"] = {save_as_gif}',
221+
f'config["output_file"] = r"{output_file}"',
222222
]
223223

224224
user_code = self.content
@@ -229,7 +229,7 @@ def run(self):
229229

230230
code = [
231231
"from manim import *",
232-
*file_writer_config_code,
232+
*config_code,
233233
*user_code,
234234
f"{clsname}().render()",
235235
]

docs/source/reference.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,6 @@ Other modules
128128
.. autosummary::
129129
:toctree: reference
130130

131-
_config
131+
config
132132
constants
133133
container

manim/__main__.py

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import sys
44
import traceback
55

6-
from manim import constants, logger, console, config, file_writer_config
6+
from manim import constants, logger, console, config
77
from manim import Scene
88
from manim.utils.module_ops import (
99
get_module,
@@ -12,38 +12,35 @@
1212
)
1313
from manim.utils.file_ops import open_file as open_media_file
1414
from manim.grpc.impl import frame_server_impl
15+
from manim.config.utils import init_dirs
1516
from manim.config.main_utils import *
1617

1718

1819
def open_file_if_needed(file_writer):
19-
if file_writer_config["verbosity"] != "DEBUG":
20+
if config["verbosity"] != "DEBUG":
2021
curr_stdout = sys.stdout
2122
sys.stdout = open(os.devnull, "w")
2223

23-
open_file = any(
24-
[file_writer_config["preview"], file_writer_config["show_in_file_browser"]]
25-
)
24+
open_file = any([config["preview"], config["show_in_file_browser"]])
25+
2626
if open_file:
2727
current_os = platform.system()
2828
file_paths = []
2929

30-
if file_writer_config["save_last_frame"]:
30+
if config["save_last_frame"]:
3131
file_paths.append(file_writer.get_image_file_path())
32-
if (
33-
file_writer_config["write_to_movie"]
34-
and not file_writer_config["save_as_gif"]
35-
):
32+
if config["write_to_movie"] and not config["save_as_gif"]:
3633
file_paths.append(file_writer.get_movie_file_path())
37-
if file_writer_config["save_as_gif"]:
34+
if config["save_as_gif"]:
3835
file_paths.append(file_writer.gif_file_path)
3936

4037
for file_path in file_paths:
41-
if file_writer_config["show_in_file_browser"]:
38+
if config["show_in_file_browser"]:
4239
open_media_file(file_path, True)
43-
if file_writer_config["preview"]:
40+
if config["preview"]:
4441
open_media_file(file_path, False)
4542

46-
if file_writer_config["verbosity"] != "DEBUG":
43+
if config["verbosity"] != "DEBUG":
4744
sys.stdout.close()
4845
sys.stdout = curr_stdout
4946

@@ -69,13 +66,10 @@ def main():
6966
# something_else_here()
7067

7168
else:
72-
update_config_with_cli(args)
73-
init_dirs(file_writer_config)
74-
75-
if file_writer_config["log_to_file"]:
76-
set_file_logger()
69+
config.digest_args(args)
70+
init_dirs(config)
7771

78-
module = get_module(file_writer_config["input_file"])
72+
module = get_module(config["input_file"])
7973
all_scene_classes = get_scene_classes_from_module(module)
8074
scene_classes_to_render = get_scenes_to_render(all_scene_classes)
8175
for SceneClass in scene_classes_to_render:

manim/camera/camera.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import cairo
1515
import numpy as np
1616

17-
from .. import logger, config, camera_config
17+
from .. import logger, config
1818
from ..constants import *
1919
from ..mobject.types.image_mobject import AbstractImageMobject
2020
from ..mobject.mobject import Mobject
@@ -53,8 +53,6 @@ class Camera(object):
5353
# Note: frame height and width will be resized to match
5454
# the pixel aspect ratio
5555
"frame_center": ORIGIN,
56-
"background_color": BLACK,
57-
"background_opacity": 1,
5856
# Points in vectorized mobjects with norm greater
5957
# than this value will be rescaled.
6058
"image_mode": "RGBA",
@@ -91,6 +89,8 @@ def __init__(self, video_quality_config, background=None, **kwargs):
9189
"frame_height",
9290
"frame_width",
9391
"frame_rate",
92+
"background_color",
93+
"background_opacity",
9494
]:
9595
setattr(self, attr, kwargs.get(attr, config[attr]))
9696

@@ -1039,9 +1039,7 @@ def adjusted_thickness(self, thickness):
10391039
10401040
"""
10411041
# TODO: This seems...unsystematic
1042-
big_sum = op.add(
1043-
camera_config["default_pixel_height"], camera_config["default_pixel_width"]
1044-
)
1042+
big_sum = op.add(config["default_pixel_height"], config["default_pixel_width"])
10451043
this_sum = op.add(self.pixel_height, self.pixel_width)
10461044
factor = fdiv(big_sum, this_sum)
10471045
return 1 + (thickness - 1) / factor

manim/config/__init__.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import logging
22
from contextlib import contextmanager
33

4-
from .utils import make_config_parser, make_logger, make_config, make_file_writer_config
4+
from .logger import make_logger
5+
from .utils import make_config_parser, ManimConfig, ManimFrame
56

67
__all__ = [
78
"logger",
89
"console",
910
"config",
10-
"file_writer_config",
11-
"camera_config",
11+
"frame",
1212
"tempconfig",
1313
]
1414

@@ -22,9 +22,8 @@
2222
logging.getLogger("PIL").setLevel(logging.INFO)
2323
logging.getLogger("matplotlib").setLevel(logging.INFO)
2424

25-
config = make_config(parser)
26-
camera_config = config
27-
file_writer_config = make_file_writer_config(parser, config)
25+
config = ManimConfig(parser)
26+
frame = ManimFrame(config)
2827

2928

3029
# This has to go here because it needs access to this module's config

manim/config/default.cfg

Lines changed: 14 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -73,16 +73,13 @@ upto_animation_number = -1
7373
media_dir = ./media
7474

7575
# --log_dir (by default "/logs", that will be put inside the media dir)
76-
log_dir = logs
76+
log_dir = {media_dir}/logs
7777

78-
# # --video_dir
79-
# video_dir = %(MEDIA_DIR)s/videos
80-
81-
# # --tex_dir
82-
# tex_dir = %(MEDIA_DIR)s/Tex
83-
84-
# # --text_dir
85-
# text_dir = %(MEDIA_DIR)s/texts
78+
# the following do not have CLI arguments but depend on media_dir
79+
video_dir = {media_dir}/videos
80+
tex_dir = {media_dir}/Tex
81+
text_dir = {media_dir}/texts
82+
images_dir = {media_dir}/images
8683

8784
# --use_js_renderer
8885
use_js_renderer = False
@@ -112,45 +109,6 @@ disable_caching = False
112109
# --tex_template
113110
tex_template =
114111

115-
# These override the previous by using -t, --transparent
116-
[transparent]
117-
png_mode = RGBA
118-
movie_file_extension = .mov
119-
background_opacity = 0
120-
121-
# These override the previous by using -k, --four_k
122-
[fourk_quality]
123-
pixel_height = 2160
124-
pixel_width = 3840
125-
frame_rate = 60
126-
127-
# These override the previous by using -e, --high_quality
128-
[high_quality]
129-
pixel_height = 1440
130-
pixel_width = 2560
131-
frame_rate = 60
132-
133-
# These override the previous by using -m, --medium_quality
134-
[medium_quality]
135-
pixel_height = 720
136-
pixel_width = 1280
137-
frame_rate = 30
138-
139-
# These override the previous by using -l, --low_quality
140-
[low_quality]
141-
pixel_height = 480
142-
pixel_width = 854
143-
frame_rate = 15
144-
145-
# These override the previous by using --dry_run
146-
# Note --dry_run overrides all of -w, -a, -s, -g, -i
147-
[dry_run]
148-
write_to_movie = False
149-
write_all = False
150-
save_last_frame = False
151-
save_pngs = False
152-
save_as_gif = False
153-
154112
# Streaming settings
155113
[streaming]
156114
live_stream_name = LiveStream
@@ -170,10 +128,11 @@ streaming_console_banner = Manim is now running in streaming mode.
170128
# under media_dir, as is the default.
171129
[custom_folders]
172130
media_dir = videos
173-
video_dir = %(media_dir)s
174-
images_dir = %(media_dir)s
175-
text_dir = %(media_dir)s/temp_files
176-
tex_dir = %(media_dir)s/temp_files
131+
video_dir = {media_dir}
132+
images_dir = {media_dir}
133+
text_dir = {media_dir}/temp_files
134+
tex_dir = {media_dir}/temp_files
135+
log_dir = {media_dir}/temp_files
177136

178137
# Rich settings
179138
[logger]
@@ -193,5 +152,6 @@ log_height = -1
193152
log_timestamps = True
194153

195154
[ffmpeg]
196-
# Uncomment the following line to manually set the loglevel for ffmpeg. See ffmpeg manpage for accepted values
197-
# loglevel = error
155+
# Uncomment the following line to manually set the loglevel for ffmpeg. See
156+
# ffmpeg manpage for accepted values
157+
loglevel = ERROR

0 commit comments

Comments
 (0)