Skip to content

Commit 25b3126

Browse files
heittprchristopher-beschbehackl
authored
Allow setting the input file via a config file (#2151)
* allow setting the input file via a config file * fix: removed partial_movie_files * Removed Extraneous Dots * added documentation * added link to docu * added test * removed test.py * reverted poetry.lock changes Co-authored-by: christopher-besch <[email protected]> Co-authored-by: Benjamin Hackl <[email protected]>
1 parent e24b71e commit 25b3126

File tree

4 files changed

+58
-5
lines changed

4 files changed

+58
-5
lines changed

manim/_config/utils.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -662,14 +662,24 @@ def digest_args(self, args: argparse.Namespace) -> "ManimConfig":
662662
digesting any other CLI arguments.
663663
664664
"""
665+
# if the input file is a config file, parse it properly
666+
if args.file.suffix == ".cfg":
667+
args.config_file = args.file
668+
669+
# if args.file is `-`, the animation code has to be taken from STDIN, so the
670+
# input file path shouldn't be absolute, since that file won't be read.
671+
if str(args.file) == "-":
672+
self.input_file = args.file
673+
665674
# if a config file has been passed, digest it first so that other CLI
666675
# flags supersede it
667676
if args.config_file:
668677
self.digest_file(args.config_file)
669678

670-
# If args.file is `-`, the animation code has to be taken from STDIN, so the
671-
# input file path shouldn't be absolute, since that file won't be read.
672-
self.input_file = Path(args.file).absolute() if args.file != "-" else args.file
679+
# read input_file from the args if it wasn't set by the config file
680+
if not self.input_file:
681+
self.input_file = Path(args.file).absolute()
682+
673683
self.scene_names = args.scene_names if args.scene_names is not None else []
674684
self.output_file = args.output_file
675685

manim/cli/render/commands.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def render(
3737
):
3838
"""Render SCENE(S) from the input FILE.
3939
40-
FILE is the file path of the script.
40+
FILE is the file path of the script or a config file.
4141
4242
SCENES is an optional list of scenes in the file.
4343
"""
@@ -95,7 +95,7 @@ def __repr__(self):
9595
return click_args
9696

9797
config.digest_args(click_args)
98-
file = args["file"]
98+
file = Path(config.input_file)
9999
if config.renderer == "opengl":
100100
from manim.renderer.opengl_renderer import OpenGLRenderer
101101

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"name": "InputFileViaCfg",
3+
"movie_metadata": {
4+
"codec_name": "h264",
5+
"width": 854,
6+
"height": 480,
7+
"avg_frame_rate": "15/1",
8+
"duration": "1.000000",
9+
"nb_frames": "15"
10+
},
11+
"section_dir_layout": [],
12+
"section_index": []
13+
}

tests/test_scene_rendering/test_cli_flags.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import itertools
2+
import os
23
import sys
34
from pathlib import Path
45

@@ -638,3 +639,32 @@ def test_mov_can_be_set_as_output_format(tmp_path, manim_cfg_file, simple_scenes
638639
assert expected_mov_path.exists(), "expected .mov file not found at " + str(
639640
expected_mov_path,
640641
)
642+
643+
644+
@pytest.mark.slow
645+
@video_comparison(
646+
"InputFileViaCfg.json",
647+
"videos/simple_scenes/480p15/SquareToCircle.mp4",
648+
)
649+
def test_input_file_via_cfg(tmp_path, manim_cfg_file, simple_scenes_path):
650+
scene_name = "SquareToCircle"
651+
with open(os.path.join(tmp_path, "manim.cfg"), "w") as file:
652+
file.write(
653+
f"""
654+
[CLI]
655+
input_file = {simple_scenes_path}
656+
"""
657+
)
658+
659+
command = [
660+
sys.executable,
661+
"-m",
662+
"manim",
663+
"-ql",
664+
"--media_dir",
665+
".",
666+
str(tmp_path),
667+
scene_name,
668+
]
669+
out, err, exit_code = capture(command, cwd=tmp_path)
670+
assert exit_code == 0, err

0 commit comments

Comments
 (0)