Skip to content

Commit 9fb1a16

Browse files
authored
Fix - as filename feature (#1005)
* Exemption from absolute filepath if filename is - * Comment why filepath is not made absolute if - is filename. * Add a test for `-` as filename feature. * Fix typo * Use subprocess instead of echo and pipe for test. * Run black * Removed unused shell mode argument.
1 parent 14df62c commit 9fb1a16

File tree

3 files changed

+25
-3
lines changed

3 files changed

+25
-3
lines changed

manim/_config/utils.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -605,7 +605,9 @@ def digest_args(self, args: argparse.Namespace) -> "ManimConfig":
605605
if args.config_file:
606606
self.digest_file(args.config_file)
607607

608-
self.input_file = Path(args.file).absolute()
608+
# If args.file is `-`, the animation code has to be taken from STDIN, so the
609+
# input file path shouldn't be absolute, since that file won't be read.
610+
self.input_file = Path(args.file).absolute() if args.file != "-" else args.file
609611
self.scene_names = args.scene_names if args.scene_names is not None else []
610612
self.output_file = args.output_file
611613

tests/test_scene_rendering/test_cli_flags.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,3 +164,22 @@ def test_custom_folders(tmp_path, manim_cfg_file, simple_scenes_path):
164164

165165
exists = (tmp_path / "SquareToCircle.png").exists()
166166
assert exists, "--custom_folders did not produce the output file"
167+
168+
169+
@pytest.mark.slow
170+
def test_dash_as_filename(tmp_path):
171+
code = "class Test(Scene):\n def construct(self):\n self.add(Circle())\n self.wait(1)"
172+
command = [
173+
"python",
174+
"-m",
175+
"manim",
176+
"-ql",
177+
"-s",
178+
"--media_dir",
179+
str(tmp_path),
180+
"-",
181+
]
182+
out, err, exit_code = capture(command, command_input=code)
183+
assert exit_code == 0, err
184+
exists = (tmp_path / "images" / "-" / "Test.png").exists()
185+
assert exists, out

tests/utils/commands.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import subprocess
22

33

4-
def capture(command, cwd=None):
4+
def capture(command, cwd=None, command_input=None):
55
proc = subprocess.Popen(
66
command,
77
stdout=subprocess.PIPE,
88
stderr=subprocess.PIPE,
9+
stdin=subprocess.PIPE,
910
encoding="utf8",
1011
cwd=cwd,
1112
)
12-
out, err = proc.communicate()
13+
out, err = proc.communicate(command_input)
1314
return out, err, proc.returncode

0 commit comments

Comments
 (0)