allow rendering scenes from any directory (#391)

This commit is contained in:
Devin Neal 2019-01-03 13:42:02 -08:00 committed by GitHub
parent 4d069db15c
commit 1de67af678
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 12 deletions

View file

@ -1,6 +1,6 @@
import argparse
import colour
import importlib
import importlib.util
import os
import sys
import types
@ -79,7 +79,7 @@ def parse_cli():
def get_module(file_name):
if file_name == "-":
module = types.ModuleType("InputModule")
module = types.ModuleType("input_scenes")
code = "from big_ol_pile_of_manim_imports import *\n\n" + sys.stdin.read()
try:
exec(code, module.__dict__)
@ -88,8 +88,11 @@ def get_module(file_name):
print(f"Failed to render scene: {str(e)}")
sys.exit(2)
else:
module_name = file_name.replace(".py", "").replace(os.sep, ".")
return importlib.import_module(module_name)
module_name = file_name.split(os.sep)[-1].replace(".py", "")
spec = importlib.util.spec_from_file_location(module_name, file_name)
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)
return module
def get_configuration(args):

View file

@ -20,14 +20,7 @@ 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"))
return guarantee_existance(os.path.join(VIDEO_DIR, scene_class.__module__))
def get_movie_output_directory(scene_class, camera_config, frame_duration):