From dec8fc5eeb24dfa1d2f693cb0b029b8723629337 Mon Sep 17 00:00:00 2001 From: Varniex Date: Mon, 16 Dec 2024 15:39:34 +0530 Subject: [PATCH 1/3] identify the scene name based on the line number --- manimlib/default_config.yml | 6 +++--- manimlib/extract_scene.py | 26 ++++++++++++++++++++------ manimlib/mobject/probability.py | 1 + 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/manimlib/default_config.yml b/manimlib/default_config.yml index 397de60ebf..1f045a5827 100644 --- a/manimlib/default_config.yml +++ b/manimlib/default_config.yml @@ -5,13 +5,13 @@ # you are running manim. For 3blue1brown, for instance, mind is # here: https://github.com/3b1b/videos/blob/master/custom_config.yml -# Alternatively, you can create it whereever you like, and on running +# Alternatively, you can create it where ever you like, and on running # manim, pass in `--config_file /path/to/custom/config/file.yml` directories: # Set this to true if you want the path to video files # to match the directory structure of the path to the - # sourcecode generating that video + # source code generating that video mirror_module_path: False # Manim may write to and read from the file system, e.g. # to render videos and to look for svg/png assets. This @@ -44,7 +44,7 @@ window: # If not full screen, the default to give it half the screen width full_screen: False # Other optional specifications that override the above include: - # position: (500, 500) # Specific position, in pixel coordiantes, for upper right corner + # position: (500, 500) # Specific position, in pixel coordinates, for upper right corner # size: (1920, 1080) # Specific size, in pixels camera: resolution: (1920, 1080) diff --git a/manimlib/extract_scene.py b/manimlib/extract_scene.py index 5509778b05..2f86a8daca 100644 --- a/manimlib/extract_scene.py +++ b/manimlib/extract_scene.py @@ -12,6 +12,7 @@ from manimlib.scene.scene import Scene from typing import TYPE_CHECKING + if TYPE_CHECKING: Module = importlib.util.types.ModuleType from typing import Optional @@ -142,7 +143,7 @@ def get_indent(code_lines: list[str], line_number: int) -> str: return n_spaces * " " -def insert_embed_line_to_module(module: Module, line_number: int): +def insert_embed_line_to_module(module: Module, run_config: Dict) -> None: """ This is hacky, but convenient. When user includes the argument "-e", it will try to recreate a file that inserts the line `self.embed()` into the end of the scene's @@ -150,27 +151,40 @@ def insert_embed_line_to_module(module: Module, line_number: int): the last line in the sourcefile which includes that string. """ lines = inspect.getsource(module).splitlines() + line_number = run_config.embed_line # Add the relevant embed line to the code indent = get_indent(lines, line_number) lines.insert(line_number, indent + "self.embed()") new_code = "\n".join(lines) + # When the user executes the `-e ` command, + # it should automatically identifies the nearest class + # defined above `` as 'scene_names'. + classes = list(filter(lambda line: line.startswith("class"), lines[:line_number])) + if classes: + from re import search + + name_search = search(r"(\w+)\(", classes[-1]) + run_config.update(scene_names=[name_search.group(1)]) + else: + log.error(f"No 'class' has been found above {line_number}!") + # Execute the code, which presumably redefines the user's # scene to include this embed line, within the relevant module. code_object = compile(new_code, module.__name__, 'exec') exec(code_object, module.__dict__) -def get_module(file_name: Optional[str], embed_line: Optional[int], is_reload: bool = False) -> Module: - module = ModuleLoader.get_module(file_name, is_reload) - if embed_line: - insert_embed_line_to_module(module, embed_line) +def get_module(run_config: Dict) -> Module: + module = ModuleLoader.get_module(run_config.file_name, run_config.is_reload) + if run_config.embed_line: + insert_embed_line_to_module(module, run_config) return module def main(scene_config: Dict, run_config: Dict): - module = get_module(run_config.file_name, run_config.embed_line, run_config.is_reload) + module = get_module(run_config) all_scene_classes = get_scene_classes(module) scenes = get_scenes_to_render(all_scene_classes, scene_config, run_config) if len(scenes) == 0: diff --git a/manimlib/mobject/probability.py b/manimlib/mobject/probability.py index 83cad718f1..128057649f 100644 --- a/manimlib/mobject/probability.py +++ b/manimlib/mobject/probability.py @@ -43,6 +43,7 @@ def __init__( fill_opacity=fill_opacity, stroke_width=stroke_width, stroke_color=stroke_color, + **kwargs ) self.default_label_scale_val = default_label_scale_val From b2df51c41a26548fb8760fd5f1bfaf0a5122b91d Mon Sep 17 00:00:00 2001 From: Varniex Date: Mon, 16 Dec 2024 21:30:12 +0530 Subject: [PATCH 2/3] resolving a minor bug in string_mobject --- manimlib/mobject/svg/string_mobject.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/manimlib/mobject/svg/string_mobject.py b/manimlib/mobject/svg/string_mobject.py index 85031d87d9..8e1631ba11 100644 --- a/manimlib/mobject/svg/string_mobject.py +++ b/manimlib/mobject/svg/string_mobject.py @@ -122,8 +122,8 @@ def mobjects_from_svg_string(self, svg_string: str) -> list[VMobject]: # of submobject which are and use those for labels unlabelled_submobs = submobs labelled_content = self.get_content(is_labelled=True) - labelled_file = self.get_file_path_by_content(labelled_content) - labelled_submobs = super().mobjects_from_file(labelled_file) + labelled_file = self.get_svg_string_by_content(labelled_content) + labelled_submobs = super().mobjects_from_svg_string(labelled_file) self.labelled_submobs = labelled_submobs self.unlabelled_submobs = unlabelled_submobs From 2d5fc0a9cf3a2b41ea517d85f56913ea19cc15d1 Mon Sep 17 00:00:00 2001 From: Varniex Date: Tue, 17 Dec 2024 00:23:39 +0530 Subject: [PATCH 3/3] removing bug of string validation --- manimlib/mobject/svg/text_mobject.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/manimlib/mobject/svg/text_mobject.py b/manimlib/mobject/svg/text_mobject.py index ac9b7a7aab..40ca5af68e 100644 --- a/manimlib/mobject/svg/text_mobject.py +++ b/manimlib/mobject/svg/text_mobject.py @@ -176,9 +176,6 @@ def __init__( self.disable_ligatures = disable_ligatures self.isolate = isolate - if not isinstance(self, Text): - self.validate_markup_string(text) - super().__init__(text, height=height, **kwargs) if self.t2g: