Skip to content

Commit 00b34f2

Browse files
3b1bSplines
andauthored
Autoreload v2 (#2268)
* Add autoreload * Typo correction * Add --autoreload to configuration docts Co-Authored-By: Splines <[email protected]> --------- Co-authored-by: Splines <[email protected]>
1 parent bafea89 commit 00b34f2

File tree

4 files changed

+21
-0
lines changed

4 files changed

+21
-0
lines changed

docs/source/getting_started/configuration.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ flag abbr function
6363
``--video_dir VIDEO_DIR`` Directory to write video
6464
``--config_file CONFIG_FILE`` Path to the custom configuration file
6565
``--log-level LOG_LEVEL`` Level of messages to Display, can be DEBUG / INFO / WARNING / ERROR / CRITICAL
66+
``--autoreload`` Automatically reload Python modules to pick up code changes across different files
6667
========================================================== ====== =====================================================================================================================================================================================================
6768

6869
custom_config

manimlib/config.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ def initialize_manim_config() -> Dict:
4545
update_file_writer_config(config, args)
4646
update_scene_config(config, args)
4747
update_run_config(config, args)
48+
update_embed_config(config, args)
4849

4950
return Dict(config)
5051

@@ -209,6 +210,12 @@ def parse_cli():
209210
"--log-level",
210211
help="Level of messages to Display, can be DEBUG / INFO / WARNING / ERROR / CRITICAL"
211212
)
213+
parser.add_argument(
214+
"--autoreload",
215+
action="store_true",
216+
help="Automatically reload Python modules to pick up code changes " +
217+
"across different files",
218+
)
212219
args = parser.parse_args()
213220
args.write_file = any([args.write_file, args.open, args.finder])
214221
return args
@@ -311,6 +318,11 @@ def update_run_config(config: dict, args: Namespace):
311318
)
312319

313320

321+
def update_embed_config(config: dict, args: Namespace):
322+
if args.autoreload:
323+
config["embed"]["autoreload"] = True
324+
325+
314326
# Helpers for the functions above
315327

316328

manimlib/default_config.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ text:
8383
alignment: "LEFT"
8484
embed:
8585
exception_mode: "Verbose"
86+
autoreload: False
8687
resolution_options:
8788
# When the user passes in -l, -m, --hd or --uhd, these are the corresponding
8889
# resolutions

manimlib/scene/scene_embed.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ def __init__(self, scene: Scene):
2929
self.enable_gui()
3030
self.ensure_frame_update_post_cell()
3131
self.ensure_flash_on_error()
32+
if manim_config.embed.autoreload:
33+
self.auto_reload()
3234

3335
def launch(self):
3436
self.shell()
@@ -139,6 +141,11 @@ def reload_scene(self, embed_line: int | None = None) -> None:
139141
print("Reloading...")
140142
self.shell.run_line_magic("exit_raise", "")
141143

144+
def auto_reload(self):
145+
"""Enables IPython autoreload for automatic reloading of modules."""
146+
self.shell.magic("load_ext autoreload")
147+
self.shell.magic("autoreload all")
148+
142149
def checkpoint_paste(
143150
self,
144151
skip: bool = False,

0 commit comments

Comments
 (0)