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()
return
reload_manager = ReloadManager()
reload_manager.args = args
reload_manager = ReloadManager(args)
reload_manager.run()

View File

@ -1,9 +1,20 @@
from __future__ import annotations
from typing import Any
from IPython.terminal.embed import KillEmbedded
import manimlib.config
import manimlib.extract_scene
from manimlib.window import Window
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from argparse import Namespace
class ReloadManager:
"""
Manages the loading and running of scenes and is called directly from the
@ -14,7 +25,6 @@ class ReloadManager:
command in the IPython shell.
"""
args: Any = None
scenes: list[Any] = []
window = None
@ -23,6 +33,9 @@ class ReloadManager:
is_reload = False
def __init__(self, cli_args: Namespace):
self.args = cli_args
def set_new_start_at_line(self, start_at_line):
"""
Sets/Updates the line number to load the scene from when reloading.
@ -36,7 +49,7 @@ class ReloadManager:
while True:
try:
# 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
except KillEmbedded:
# Requested via the `exit_raise` IPython runline magic
@ -50,18 +63,12 @@ class ReloadManager:
except KeyboardInterrupt:
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.
"""
import manimlib.config
import manimlib.extract_scene
# 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)
if self.start_at_line is not None:
self.args.embed = str(self.start_at_line)
# Args to Config
scene_config = manimlib.config.get_scene_config(self.args)