Skip to content

armgit / manim

Public Imported from GitHub
0

A community-maintained Python framework for creating mathematical animations.

support for inline scenes

Devin Neal9366accf593f
diff --git a/manimlib/config.py b/manimlib/config.py
index a53e2f59c..7cef66f10 100644
--- a/manimlib/config.py
+++ b/manimlib/config.py
@@ -2,6 +2,7 @@ import argparse
import colour
import os
import sys
+import types
import manimlib.constants
@@ -70,6 +71,17 @@ def parse_cli():
sys.exit(2)
+def get_module(file_name):
+ if file_name == "-":
+ module = types.ModuleType("InputModule")
+ code = "from big_ol_pile_of_manim_imports import *\n\n" + sys.stdin.read()
+ exec(code, module.__dict__)
+ return module
+ else:
+ module_name = file_name.replace(".py", "").replace(os.sep, ".")
+ return importlib.import_module(module_name)
+
+
def get_configuration(args):
if args.output_name is not None:
output_name_root, output_name_ext = os.path.splitext(
@@ -86,7 +98,7 @@ def get_configuration(args):
output_name = args.output_name
config = {
- "file": args.file,
+ "module": get_module(args.file),
"scene_name": args.scene_name,
"open_video_upon_completion": args.preview,
"show_file_in_finder": args.show_file_in_finder,
diff --git a/manimlib/extract_scene.py b/manimlib/extract_scene.py
index e85eaa780..428dea17d 100644
--- a/manimlib/extract_scene.py
+++ b/manimlib/extract_scene.py
@@ -97,13 +97,8 @@ def get_scene_classes(scene_names_to_classes, config):
return prompt_user_for_choice(scene_names_to_classes)
-def get_module(file_name):
- module_name = file_name.replace(".py", "").replace(os.sep, ".")
- return importlib.import_module(module_name)
-
-
def main(config):
- module = get_module(config["file"])
+ module = config["module"]
scene_names_to_classes = dict(inspect.getmembers(module, is_scene))
scene_kwargs = dict([
diff --git a/manimlib/utils/output_directory_getters.py b/manimlib/utils/output_directory_getters.py
index 8e8b46dd2..972bc2cdc 100644
--- a/manimlib/utils/output_directory_getters.py
+++ b/manimlib/utils/output_directory_getters.py
@@ -20,12 +20,14 @@ def guarantee_existance(path):
def get_scene_output_directory(scene_class):
- file_path = os.path.abspath(inspect.getfile(scene_class))
-
- file_path = os.path.relpath(file_path, THIS_DIR)
- file_path = file_path.replace(".pyc", "")
- file_path = file_path.replace(".py", "")
- return guarantee_existance(os.path.join(VIDEO_DIR, file_path))
+ try:
+ file_path = os.path.abspath(inspect.getfile(scene_class))
+ file_path = os.path.relpath(file_path, THIS_DIR)
+ file_path = file_path.replace(".pyc", "")
+ file_path = file_path.replace(".py", "")
+ return guarantee_existance(os.path.join(VIDEO_DIR, file_path))
+ except TypeError:
+ return guarantee_existance(os.path.join(VIDEO_DIR, "input_scenes"))
def get_movie_output_directory(scene_class, camera_config, frame_duration):