Repository: ManimCommunity/manim

Issue:
Renderer only uses one rendering mode for all Scenes in a file
## Description of bug / unexpected behavior
<!-- Add a clear and concise description of the problem you encountered. -->

When running `manim animations.py -ql -a`, all of the Scenes are rendered as _either_ .png files _or_ .mp4 files.
For example, if the first Scene in 'animations.py' has no animation, then manim will decide to render that Scene to a .png.
However, then if the next Scene has some animation, then manim will not intelligently switch to rendering .mp4, and instead will produce a .png containing the last frame of the intended animation.


## Expected behavior
<!-- Add a clear and concise description of what you expected to happen. -->

If there are some Scenes with animations and some still Scenes in a file, when rendering all Scenes at once, manim should decide for each Scene whether to render to a .png or to an .mp4, based on whether there is animation or not.


## How to reproduce the issue
<!-- Provide a piece of code illustrating the undesired behavior. -->

<details><summary>Code for reproducing the problem</summary>

```py
Paste your code here.
```

</details>


## Additional media files
<!-- Paste in the files manim produced on rendering the code above. -->

<details><summary>Images/GIFs</summary>

<!-- PASTE MEDIA HERE -->

</details>


## Logs
<details><summary>Terminal output</summary>
<!-- Add "-v DEBUG" when calling manim to generate more detailed logs -->

```
PASTE HERE OR PROVIDE LINK TO https://pastebin.com/ OR SIMILAR
```

<!-- Insert screenshots here (only when absolutely necessary, we prefer copy/pasted output!) -->

</details>


## System specifications

<details><summary>System Details</summary>

- OS (with version, e.g Windows 10 v2004 or macOS 10.15 (Catalina)):
- RAM:
- Python version (`python/py/python3 --version`):
- Installed modules (provide output from `pip list`):
```
PASTE HERE
```
</details>

<details><summary>LaTeX details</summary>

+ LaTeX distribution (e.g. TeX Live 2020):
+ Installed LaTeX packages:
<!-- output of `tlmgr list --only-installed` for TeX Live or a screenshot of the Packages page for MikTeX -->
</details>

<details><summary>FFMPEG</summary>

Output of `ffmpeg -version`:

```
PASTE HERE
```
</details>

## Additional comments
<!-- Add further context that you think might be relevant for this issue here. -->



Discussion:

Resolving patch:
diff --git a/manim/cli/render/commands.py b/manim/cli/render/commands.py
--- a/manim/cli/render/commands.py
+++ b/manim/cli/render/commands.py
@@ -16,6 +16,7 @@
 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 __repr__(self):
             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 __repr__(self):
     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)


Test patch:
diff --git a/tests/test_scene_rendering/infallible_scenes.py b/tests/test_scene_rendering/infallible_scenes.py
--- 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 @@ def construct(self):
 
 
 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
--- 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 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
--- a/tests/test_scene_rendering/test_cli_flags.py
+++ b/tests/test_scene_rendering/test_cli_flags.py
@@ -9,7 +9,7 @@
 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"