mirror of
https://github.com/3b1b/manim.git
synced 2025-09-01 00:48:45 +00:00
allow rendering scenes from any directory (#391)
This commit is contained in:
parent
4d069db15c
commit
1de67af678
2 changed files with 8 additions and 12 deletions
|
@ -1,6 +1,6 @@
|
||||||
import argparse
|
import argparse
|
||||||
import colour
|
import colour
|
||||||
import importlib
|
import importlib.util
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import types
|
import types
|
||||||
|
@ -79,7 +79,7 @@ def parse_cli():
|
||||||
|
|
||||||
def get_module(file_name):
|
def get_module(file_name):
|
||||||
if 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()
|
code = "from big_ol_pile_of_manim_imports import *\n\n" + sys.stdin.read()
|
||||||
try:
|
try:
|
||||||
exec(code, module.__dict__)
|
exec(code, module.__dict__)
|
||||||
|
@ -88,8 +88,11 @@ def get_module(file_name):
|
||||||
print(f"Failed to render scene: {str(e)}")
|
print(f"Failed to render scene: {str(e)}")
|
||||||
sys.exit(2)
|
sys.exit(2)
|
||||||
else:
|
else:
|
||||||
module_name = file_name.replace(".py", "").replace(os.sep, ".")
|
module_name = file_name.split(os.sep)[-1].replace(".py", "")
|
||||||
return importlib.import_module(module_name)
|
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):
|
def get_configuration(args):
|
||||||
|
|
|
@ -20,14 +20,7 @@ def guarantee_existance(path):
|
||||||
|
|
||||||
|
|
||||||
def get_scene_output_directory(scene_class):
|
def get_scene_output_directory(scene_class):
|
||||||
try:
|
return guarantee_existance(os.path.join(VIDEO_DIR, scene_class.__module__))
|
||||||
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):
|
def get_movie_output_directory(scene_class, camera_config, frame_duration):
|
||||||
|
|
Loading…
Add table
Reference in a new issue