support for inline scenes

This commit is contained in:
Devin Neal
2018-12-24 12:49:10 -08:00
parent 3543a750ba
commit 9366accf59
3 changed files with 22 additions and 13 deletions

View File

@ -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,

View File

@ -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([

View File

@ -20,12 +20,14 @@ def guarantee_existance(path):
def get_scene_output_directory(scene_class):
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):