Skip to content

armgit / manim

Public Imported from GitHub
0

A community-maintained Python framework for creating mathematical animations.

Use tempconfig for every scene render (#2567)

ad_chaosf1c5b6b372f8
diff --git a/manim/cli/render/commands.py b/manim/cli/render/commands.py
index bc6315731..97ba883ff 100644
--- a/manim/cli/render/commands.py
+++ b/manim/cli/render/commands.py
@@ -16,6 +16,7 @@ import cloup
import requests
from ... import __version__, config, console, error_console, logger
+from ..._config import tempconfig
from ...constants import EPILOG
from ...utils.module_ops import scene_classes_from_file
from .ease_of_access_options import ease_of_access_options
@@ -97,8 +98,9 @@ def render(
keep_running = True
while keep_running:
for SceneClass in scene_classes_from_file(file):
- scene = SceneClass(renderer)
- rerun = scene.render()
+ with tempconfig(config):
+ scene = SceneClass(renderer)
+ rerun = scene.render()
if rerun or config["write_all"]:
renderer.num_plays = 0
continue
@@ -114,8 +116,9 @@ def render(
else:
for SceneClass in scene_classes_from_file(file):
try:
- scene = SceneClass()
- scene.render()
+ with tempconfig(config):
+ scene = SceneClass()
+ scene.render()
except Exception:
error_console.print_exception()
sys.exit(1)
diff --git a/tests/test_scene_rendering/infallible_scenes.py b/tests/test_scene_rendering/infallible_scenes.py
index b9f1e1ca0..07290128a 100644
--- a/tests/test_scene_rendering/infallible_scenes.py
+++ b/tests/test_scene_rendering/infallible_scenes.py
@@ -1,6 +1,6 @@
from __future__ import annotations
-from manim import *
+from manim import Scene, Square
class Wait1(Scene):
@@ -9,5 +9,10 @@ class Wait1(Scene):
class Wait2(Scene):
+ def construct(self):
+ self.add(Square())
+
+
+class Wait3(Scene):
def construct(self):
self.wait(2)
diff --git a/tests/test_scene_rendering/opengl/test_cli_flags_opengl.py b/tests/test_scene_rendering/opengl/test_cli_flags_opengl.py
index 2d38bc58b..876b011bd 100644
--- a/tests/test_scene_rendering/opengl/test_cli_flags_opengl.py
+++ b/tests/test_scene_rendering/opengl/test_cli_flags_opengl.py
@@ -9,7 +9,7 @@ from click.testing import CliRunner
from PIL import Image
from manim import capture, get_video_metadata
-from manim.__main__ import main
+from manim.__main__ import __version__, main
from manim.utils.file_ops import add_version_before_extension
from tests.utils.video_tester import video_comparison
@@ -341,10 +341,17 @@ def test_a_flag(tmp_path, manim_cfg_file, infallible_scenes_path):
assert one_is_not_empty, "running manim with -a flag did not render the first scene"
two_is_not_empty = (
- tmp_path / "videos" / "infallible_scenes" / "480p15" / "Wait2.mp4"
+ tmp_path / "images" / "infallible_scenes" / f"Wait2_ManimCE_v{__version__}.png"
).is_file()
assert (
two_is_not_empty
+ ), "running manim with -a flag did not render an image, possible leak of the config dictionary"
+
+ three_is_not_empty = (
+ tmp_path / "videos" / "infallible_scenes" / "480p15" / "Wait3.mp4"
+ ).is_file()
+ assert (
+ three_is_not_empty
), "running manim with -a flag did not render the second scene"
diff --git a/tests/test_scene_rendering/test_cli_flags.py b/tests/test_scene_rendering/test_cli_flags.py
index f1d0f4382..d48f5aac3 100644
--- a/tests/test_scene_rendering/test_cli_flags.py
+++ b/tests/test_scene_rendering/test_cli_flags.py
@@ -9,7 +9,7 @@ from click.testing import CliRunner
from PIL import Image
from manim import capture, get_video_metadata
-from manim.__main__ import main
+from manim.__main__ import __version__, main
from manim.utils.file_ops import add_version_before_extension
from ..utils.video_tester import video_comparison
@@ -229,7 +229,7 @@ def test_a_flag(tmp_path, manim_cfg_file, infallible_scenes_path):
"-a",
infallible_scenes_path,
]
- out, err, exit_code = capture(command)
+ _, err, exit_code = capture(command)
assert exit_code == 0, err
one_is_not_empty = (
@@ -238,10 +238,17 @@ def test_a_flag(tmp_path, manim_cfg_file, infallible_scenes_path):
assert one_is_not_empty, "running manim with -a flag did not render the first scene"
two_is_not_empty = (
- tmp_path / "videos" / "infallible_scenes" / "480p15" / "Wait2.mp4"
+ tmp_path / "images" / "infallible_scenes" / f"Wait2_ManimCE_v{__version__}.png"
).is_file()
assert (
two_is_not_empty
+ ), "running manim with -a flag did not render an image, possible leak of the config dictionary."
+
+ three_is_not_empty = (
+ tmp_path / "videos" / "infallible_scenes" / "480p15" / "Wait3.mp4"
+ ).is_file()
+ assert (
+ three_is_not_empty
), "running manim with -a flag did not render the second scene"