Repository: ManimCommunity/manim

Issue:
Document and test the '-' file name command line argument
The `get_module` function in `extract_scene.py` allows the user to input the code for a Scene from stdin, but only when the argument passed as file name is `-`. This should be documented somewhere. At the very least, the `-h` flag should mention this possibility.


Discussion:
That's weird, but it could be very useful
We should implement that but with a proper new flag
TBH I think that refactoring this into something usable, alongside with the necessary documentation and testing is going to be much more hassle than it's worth. It's unclear to me that the use cases merit the work needed here.
It's been two weeks and I don't hear anyone making arguments in favor of keeping this. If no one speaks up in a few more days, I'll write a PR to remove it.
> It's been two weeks and I don't hear anyone making arguments in favor of keeping this. If no one speaks up in a few more days, I'll write a PR to remove it.

@leotrs Can we please keep it in? It would make some applications (say, like writing a Discord Manim rendering bot) a lot easier...

EDIT: On the other hand... I can't really get it to work, so um, I think it's broken? If it is, then it should probably be removed.
You're right in that it'd be nice to have, but you're also right in that it's broken.

For bot/application purposes, it'd be simpler to store the code in a temporary file and then send that to manim, no?

I'm in favor of deleting it.
> You're right in that it'd be nice to have, but you're also right in that it's broken.

So it actually _is_ broken? No point in keeping it then.

> For bot/application purposes, it'd be simpler to store the code in a temporary file and then send that to manim, no?

Well, that's what my Manim rendering bot currently does, but if this feature worked, it would have made the load on the host a lot less...

> I'm in favor of deleting it.

Agreed. No use in having something that doesn't work.
@ManimCommunity/core anyone against removing this?

Resolving patch:
diff --git a/manim/__main__.py b/manim/__main__.py
--- 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,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


Test patch:
diff --git a/tests/test_cli/dash_test_script.txt b/tests/test_cli/dash_test_script.txt
new file mode 100644
--- /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
--- 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)