Repository: ManimCommunity/manim
Pull request: Allow the user to type manim code when using - as filename.
Fixes the manim feature that allowed end users to enter manim code on the spot if they ran the `manim` command with `-` as the argument.

We just needed to import `types`, a built-in module, and the rest just fell into place.

I have added some log statements that make it clearer as to exactly what the end user had to do.

This is related to #75 which talks about removing it entirely since it didn't work as intended. Since this fixes it, will this close #75 ?


Problem statement:
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.

Hints from issue 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?

Commit message: Allow the user to type manim code when using - as filename.

Add log statements informing the user of what they must do.

Patch to review:
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


Code review comments:
diff_hunk: @@ -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):")
path: manim/__main__.py
text: @user1:
<kbd>Ctrl</kbd> + <kbd>Z</kbd> for Windows.

@author:
Thanks! I'll be sure to add that in my next commit which should be in a few hours, after I wake up.

@author:
Done.

diff_hunk: @@ -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:
path: manim/__main__.py
text: @user1:
Didn't there used to be a line here that added `from manim import *` to the top of the file? Would be better to keep it that way imo since I see this option being used mostly for quick testing and prototyping manim scenes so adding a `from manim import *` everytime seems redundant.

@author:
Huh. Don't recall seeing that. In any case I'll add it in, in a few hours, once I'm awake.

@author:
Done.