Skip to content

armgit / manim

Public Imported from GitHub
0

A community-maintained Python framework for creating mathematical animations.

Update from Upstream. (#5)

Aathish50de10731ad5
diff --git a/manim/__main__.py b/manim/__main__.py
index 63f7bebba..e47e405d9 100644
--- a/manim/__main__.py
+++ b/manim/__main__.py
@@ -6,6 +6,7 @@ import sys
import re
import traceback
import importlib.util
+import types
from .config import file_writer_config
from .scene.scene import Scene
@@ -123,7 +124,12 @@ 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 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...")
+ code="from manim import *\n"+code
+ logger.info("Rendering animation from typed code...")
try:
exec(code, module.__dict__)
return module
diff --git a/manim/config.py b/manim/config.py
index d0d1388a1..97ba59443 100644
--- a/manim/config.py
+++ b/manim/config.py
@@ -176,8 +176,9 @@ def _parse_file_writer_config(config_parser, args):
def _parse_cli(arg_list, input=True):
parser = argparse.ArgumentParser(
+ formatter_class=argparse.RawDescriptionHelpFormatter,
description='Animation engine for explanatory math videos',
- epilog='Made with <3 by the manim community devs'
+ epilog=f"Made with {'<3' if os.name == 'nt' else '❤ '} by the manim community devs"
)
if input:
parser.add_argument(
diff --git a/tests/test_cli/dash_test_script.txt b/tests/test_cli/dash_test_script.txt
new file mode 100644
index 000000000..e896e1327
--- /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 ebe4462b8..eb1e2c2c0 100644
--- a/tests/test_cli/test_cli.py
+++ b/tests/test_cli/test_cli.py
@@ -4,10 +4,11 @@ from shutil import rmtree
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)
+
+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)