Slightly simplify ReloadManager

This commit is contained in:
Grant Sanderson 2024-12-09 16:14:27 -06:00
parent bf81d94362
commit 6d0b23f914
2 changed files with 19 additions and 13 deletions

View file

@ -22,8 +22,7 @@ def main():
manimlib.utils.init_config.init_customization() manimlib.utils.init_config.init_customization()
return return
reload_manager = ReloadManager() reload_manager = ReloadManager(args)
reload_manager.args = args
reload_manager.run() reload_manager.run()

View file

@ -1,9 +1,20 @@
from __future__ import annotations
from typing import Any from typing import Any
from IPython.terminal.embed import KillEmbedded from IPython.terminal.embed import KillEmbedded
import manimlib.config
import manimlib.extract_scene
from manimlib.window import Window from manimlib.window import Window
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from argparse import Namespace
class ReloadManager: class ReloadManager:
""" """
Manages the loading and running of scenes and is called directly from the Manages the loading and running of scenes and is called directly from the
@ -14,7 +25,6 @@ class ReloadManager:
command in the IPython shell. command in the IPython shell.
""" """
args: Any = None
scenes: list[Any] = [] scenes: list[Any] = []
window = None window = None
@ -23,6 +33,9 @@ class ReloadManager:
is_reload = False is_reload = False
def __init__(self, cli_args: Namespace):
self.args = cli_args
def set_new_start_at_line(self, start_at_line): def set_new_start_at_line(self, start_at_line):
""" """
Sets/Updates the line number to load the scene from when reloading. Sets/Updates the line number to load the scene from when reloading.
@ -36,7 +49,7 @@ class ReloadManager:
while True: while True:
try: try:
# blocking call since a scene will init an IPython shell() # blocking call since a scene will init an IPython shell()
self.retrieve_scenes_and_run(self.start_at_line) self.retrieve_scenes_and_run()
return return
except KillEmbedded: except KillEmbedded:
# Requested via the `exit_raise` IPython runline magic # Requested via the `exit_raise` IPython runline magic
@ -50,18 +63,12 @@ class ReloadManager:
except KeyboardInterrupt: except KeyboardInterrupt:
break break
def retrieve_scenes_and_run(self, overwrite_start_at_line: int | None = None): def retrieve_scenes_and_run(self):
""" """
Creates a new configuration based on the CLI args and runs the scenes. Creates a new configuration based on the CLI args and runs the scenes.
""" """
import manimlib.config if self.start_at_line is not None:
import manimlib.extract_scene self.args.embed = str(self.start_at_line)
# Args
if self.args is None:
raise RuntimeError("Fatal error: No args were passed to the ReloadManager")
if overwrite_start_at_line is not None:
self.args.embed = str(overwrite_start_at_line)
# Args to Config # Args to Config
scene_config = manimlib.config.get_scene_config(self.args) scene_config = manimlib.config.get_scene_config(self.args)