Skip to content

Commit 999d81e

Browse files
Phosphorescenttbehacklpre-commit-ci[bot]
authored
Fixed issue with manim init scene SCENE_NAME filename.py and removed necessity of main.py to be present in working directory (#2870)
* Fixed .py issue with manim init scene SCENE_NAME filename.py and removed necessity of main.py file to be present. * fixed a problem when passing file name * added interface test * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci Co-authored-by: Benjamin Hackl <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 02f6268 commit 999d81e

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

manim/cli/init/commands.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,6 @@ def scene(**args):
149149
150150
FILE is the name of file in which the SCENE will be inserted.
151151
"""
152-
if not Path("main.py").exists():
153-
raise FileNotFoundError(f"{Path('main.py')} : Not a valid project directory.")
154-
155152
template_name = click.prompt(
156153
"template",
157154
type=click.Choice(get_template_names(), False),
@@ -163,8 +160,12 @@ def scene(**args):
163160
scene = scene.replace(template_name + "Template", args["scene_name"], 1)
164161

165162
if args["file_name"]:
166-
file_name = Path(args["file_name"] + ".py")
163+
if args["file_name"][-3:] == ".py":
164+
file_name = args["file_name"]
165+
else:
166+
file_name = args["file_name"] + ".py"
167167

168+
file_name = Path(file_name)
168169
if file_name.is_file():
169170
# file exists so we are going to append new scene to that file
170171
with open(file_name, "a") as f:

tests/interface/test_commands.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,28 @@ def test_manim_init_project(tmp_path):
9393
assert (Path(tmp_dir) / "testproject/manim.cfg").exists()
9494

9595

96+
def test_manim_init_scene(tmp_path):
97+
command_named = ["init", "scene", "NamedFileTestScene", "my_awesome_file.py"]
98+
command_unnamed = ["init", "scene", "DefaultFileTestScene"]
99+
runner = CliRunner()
100+
with runner.isolated_filesystem(temp_dir=tmp_path) as tmp_dir:
101+
result = runner.invoke(
102+
main, command_named, prog_name="manim", input="Default\n"
103+
)
104+
assert not result.exception
105+
assert (Path(tmp_dir) / "my_awesome_file.py").exists()
106+
with open(Path(tmp_dir) / "my_awesome_file.py") as f:
107+
file_content = f.read()
108+
assert "NamedFileTestScene(Scene):" in file_content
109+
result = runner.invoke(
110+
main, command_unnamed, prog_name="manim", input="Default\n"
111+
)
112+
assert (Path(tmp_dir) / "main.py").exists()
113+
with open(Path(tmp_dir) / "main.py") as f:
114+
file_content = f.read()
115+
assert "DefaultFileTestScene(Scene):" in file_content
116+
117+
96118
def test_manim_new_command():
97119
command = ["new"]
98120
runner = CliRunner()

0 commit comments

Comments
 (0)