From 293ee1940aeae09f212eb0d120853b7b894bc696 Mon Sep 17 00:00:00 2001 From: Aathish Sivasubrahmanian Date: Tue, 14 Jul 2020 22:52:57 +0530 Subject: [PATCH 1/4] Allow the user to type manim code when using - as filename. Add log statements informing the user of what they must do. --- manim/__main__.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/manim/__main__.py b/manim/__main__.py index 63f7bebba4..0bd7225e54 100644 --- a/manim/__main__.py +++ b/manim/__main__.py @@ -6,6 +6,7 @@ import re import traceback import importlib.util +import types from .config import file_writer_config from .scene.scene import Scene @@ -123,7 +124,9 @@ def get_scene_classes_from_module(module): def get_module(file_name): if file_name == "-": module = types.ModuleType("input_scenes") + logger.info("Enter the code for your animation and end with an EOF (usually CTRL+D):") code = sys.stdin.read() + logger.info("Rendering animation from typed code...") try: exec(code, module.__dict__) return module From b28b9a2cc8225388accc0aac293632f448ee96af Mon Sep 17 00:00:00 2001 From: Aathish Sivasubrahmanian Date: Wed, 15 Jul 2020 08:16:45 +0530 Subject: [PATCH 2/4] Automatically import manim if not imported. Mention EOF macro for Windows as well. --- manim/__main__.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/manim/__main__.py b/manim/__main__.py index 0bd7225e54..2e062f822e 100644 --- a/manim/__main__.py +++ b/manim/__main__.py @@ -124,8 +124,11 @@ def get_scene_classes_from_module(module): def get_module(file_name): if file_name == "-": module = types.ModuleType("input_scenes") - logger.info("Enter the code for your animation and end with an EOF (usually CTRL+D):") + logger.info("Enter the animation's code & end with an EOF (CTRL+D or CTRL+Z on Windows):") code = sys.stdin.read() + if not code.startswith("from manim import"): + logger.warn("Didn't find an import statement for Manim. Importing automatically...") + code="from manim import *\n"+code logger.info("Rendering animation from typed code...") try: exec(code, module.__dict__) From f89b6cf57418da6d595dda809d415c9c9810e783 Mon Sep 17 00:00:00 2001 From: Aathish Sivasubrahmanian Date: Wed, 15 Jul 2020 08:46:40 +0530 Subject: [PATCH 3/4] Clarify on which EOF macro is used by which OS. --- manim/__main__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manim/__main__.py b/manim/__main__.py index 2e062f822e..e47e405d95 100644 --- a/manim/__main__.py +++ b/manim/__main__.py @@ -124,7 +124,7 @@ def get_scene_classes_from_module(module): def get_module(file_name): if file_name == "-": module = types.ModuleType("input_scenes") - logger.info("Enter the animation's code & end with an EOF (CTRL+D or CTRL+Z on Windows):") + logger.info("Enter the animation's code & end with an EOF (CTRL+D on Linux/Unix, CTRL+Z on Windows):") code = sys.stdin.read() if not code.startswith("from manim import"): logger.warn("Didn't find an import statement for Manim. Importing automatically...") From 7cd6216c5fce153af604d3e66adada59888b20ae Mon Sep 17 00:00:00 2001 From: Aathish Date: Wed, 15 Jul 2020 16:44:15 +0530 Subject: [PATCH 4/4] Add test for the dash-as-filename feature. (#4) * Test by piping normal text to subprocess. * Change ci.yml to test this branch. * Simulate typing manim code by reading from file. * Add file to read from. * Skip test_dash_as_name, as it fails on Windows. * Rename file used by dash test * Removed an unnecessary function call. Co-authored-by: Aathish Sivasubrahmanian --- tests/test_cli/dash_test_script.txt | 5 +++++ tests/test_cli/test_cli.py | 17 ++++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 tests/test_cli/dash_test_script.txt diff --git a/tests/test_cli/dash_test_script.txt b/tests/test_cli/dash_test_script.txt new file mode 100644 index 0000000000..e896e13276 --- /dev/null +++ b/tests/test_cli/dash_test_script.txt @@ -0,0 +1,5 @@ +# from manim import * +class Dash_Test(Scene): + def construct(self): + self.play(ReplacementTransform(Square(),Circle())) + self.wait(2) \ No newline at end of file diff --git a/tests/test_cli/test_cli.py b/tests/test_cli/test_cli.py index ebe4462b86..eb1e2c2c0d 100644 --- a/tests/test_cli/test_cli.py +++ b/tests/test_cli/test_cli.py @@ -4,10 +4,11 @@ import pytest -def capture(command): +def capture(command,instream=None): proc = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, + stdin=instream ) out, err = proc.communicate() return out, err, proc.returncode @@ -44,3 +45,17 @@ def test_WriteStuff(python_version): assert os.path.exists(os.path.join( path_output, "videos", "basic_scenes", "480p15", "WriteStuff.mp4")), err rmtree(path_output) + +@pytest.mark.skip_end_to_end +def test_dash_as_name(python_version): + """Simulate using - as a filename. Intended to test the feature that allows end users to type manim code on the spot.""" + path_output = os.path.join("tests_cache", "media_temp") + command = [python_version, "-m", "manim", "-", "-l", "--media_dir", path_output] + out, err, exitcode = capture( + command, + open(os.path.join(os.path.dirname(__file__), "dash_test_script.txt")) + ) + assert exitcode == 0, err + assert os.path.exists(os.path.join( + path_output, "videos", "-", "480p15", "Dash_Test.mp4")), err + rmtree(path_output)