Skip to content

Commit f1c5b6b

Browse files
ad-chaospre-commit-ci[bot]behackl
authored
Use tempconfig for every scene render (#2567)
* Use tempconfig instead of modifying the config * Extended the -a flag test * Update tests * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Benjamin Hackl <[email protected]>
1 parent ad38f6a commit f1c5b6b

File tree

4 files changed

+32
-10
lines changed

4 files changed

+32
-10
lines changed

manim/cli/render/commands.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import requests
1717

1818
from ... import __version__, config, console, error_console, logger
19+
from ..._config import tempconfig
1920
from ...constants import EPILOG
2021
from ...utils.module_ops import scene_classes_from_file
2122
from .ease_of_access_options import ease_of_access_options
@@ -97,8 +98,9 @@ def __repr__(self):
9798
keep_running = True
9899
while keep_running:
99100
for SceneClass in scene_classes_from_file(file):
100-
scene = SceneClass(renderer)
101-
rerun = scene.render()
101+
with tempconfig(config):
102+
scene = SceneClass(renderer)
103+
rerun = scene.render()
102104
if rerun or config["write_all"]:
103105
renderer.num_plays = 0
104106
continue
@@ -114,8 +116,9 @@ def __repr__(self):
114116
else:
115117
for SceneClass in scene_classes_from_file(file):
116118
try:
117-
scene = SceneClass()
118-
scene.render()
119+
with tempconfig(config):
120+
scene = SceneClass()
121+
scene.render()
119122
except Exception:
120123
error_console.print_exception()
121124
sys.exit(1)
Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from __future__ import annotations
22

3-
from manim import *
3+
from manim import Scene, Square
44

55

66
class Wait1(Scene):
@@ -9,5 +9,10 @@ def construct(self):
99

1010

1111
class Wait2(Scene):
12+
def construct(self):
13+
self.add(Square())
14+
15+
16+
class Wait3(Scene):
1217
def construct(self):
1318
self.wait(2)

tests/test_scene_rendering/opengl/test_cli_flags_opengl.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from PIL import Image
1010

1111
from manim import capture, get_video_metadata
12-
from manim.__main__ import main
12+
from manim.__main__ import __version__, main
1313
from manim.utils.file_ops import add_version_before_extension
1414
from tests.utils.video_tester import video_comparison
1515

@@ -341,10 +341,17 @@ def test_a_flag(tmp_path, manim_cfg_file, infallible_scenes_path):
341341
assert one_is_not_empty, "running manim with -a flag did not render the first scene"
342342

343343
two_is_not_empty = (
344-
tmp_path / "videos" / "infallible_scenes" / "480p15" / "Wait2.mp4"
344+
tmp_path / "images" / "infallible_scenes" / f"Wait2_ManimCE_v{__version__}.png"
345345
).is_file()
346346
assert (
347347
two_is_not_empty
348+
), "running manim with -a flag did not render an image, possible leak of the config dictionary"
349+
350+
three_is_not_empty = (
351+
tmp_path / "videos" / "infallible_scenes" / "480p15" / "Wait3.mp4"
352+
).is_file()
353+
assert (
354+
three_is_not_empty
348355
), "running manim with -a flag did not render the second scene"
349356

350357

tests/test_scene_rendering/test_cli_flags.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from PIL import Image
1010

1111
from manim import capture, get_video_metadata
12-
from manim.__main__ import main
12+
from manim.__main__ import __version__, main
1313
from manim.utils.file_ops import add_version_before_extension
1414

1515
from ..utils.video_tester import video_comparison
@@ -229,7 +229,7 @@ def test_a_flag(tmp_path, manim_cfg_file, infallible_scenes_path):
229229
"-a",
230230
infallible_scenes_path,
231231
]
232-
out, err, exit_code = capture(command)
232+
_, err, exit_code = capture(command)
233233
assert exit_code == 0, err
234234

235235
one_is_not_empty = (
@@ -238,10 +238,17 @@ def test_a_flag(tmp_path, manim_cfg_file, infallible_scenes_path):
238238
assert one_is_not_empty, "running manim with -a flag did not render the first scene"
239239

240240
two_is_not_empty = (
241-
tmp_path / "videos" / "infallible_scenes" / "480p15" / "Wait2.mp4"
241+
tmp_path / "images" / "infallible_scenes" / f"Wait2_ManimCE_v{__version__}.png"
242242
).is_file()
243243
assert (
244244
two_is_not_empty
245+
), "running manim with -a flag did not render an image, possible leak of the config dictionary."
246+
247+
three_is_not_empty = (
248+
tmp_path / "videos" / "infallible_scenes" / "480p15" / "Wait3.mp4"
249+
).is_file()
250+
assert (
251+
three_is_not_empty
245252
), "running manim with -a flag did not render the second scene"
246253

247254

0 commit comments

Comments
 (0)