Skip to content

armgit / manim

Public Imported from GitHub
0

A community-maintained Python framework for creating mathematical animations.

allow rendering scenes from any directory (#391)

Devin Neal1de67af6784b
diff --git a/manimlib/config.py b/manimlib/config.py
index 080e86a0b..cdae8d8e6 100644
--- a/manimlib/config.py
+++ b/manimlib/config.py
@@ -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):
diff --git a/manimlib/utils/output_directory_getters.py b/manimlib/utils/output_directory_getters.py
index 972bc2cdc..b1a536c8b 100644
--- a/manimlib/utils/output_directory_getters.py
+++ b/manimlib/utils/output_directory_getters.py
@@ -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):