Autoreload v2 (#2268)
Some checks are pending
docs / build up document and deploy (push) Waiting to run

* Add autoreload

* Typo correction

* Add --autoreload to configuration docts

Co-Authored-By: Splines <37160523+Splines@users.noreply.github.com>

---------

Co-authored-by: Splines <37160523+Splines@users.noreply.github.com>
This commit is contained in:
Grant Sanderson 2024-12-12 08:52:03 -06:00 committed by GitHub
parent bafea89ac9
commit 00b34f2020
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 21 additions and 0 deletions

View file

@ -63,6 +63,7 @@ flag abbr function
``--video_dir VIDEO_DIR`` Directory to write video ``--video_dir VIDEO_DIR`` Directory to write video
``--config_file CONFIG_FILE`` Path to the custom configuration file ``--config_file CONFIG_FILE`` Path to the custom configuration file
``--log-level LOG_LEVEL`` Level of messages to Display, can be DEBUG / INFO / WARNING / ERROR / CRITICAL ``--log-level LOG_LEVEL`` Level of messages to Display, can be DEBUG / INFO / WARNING / ERROR / CRITICAL
``--autoreload`` Automatically reload Python modules to pick up code changes across different files
========================================================== ====== ===================================================================================================================================================================================================== ========================================================== ====== =====================================================================================================================================================================================================
custom_config custom_config

View file

@ -45,6 +45,7 @@ def initialize_manim_config() -> Dict:
update_file_writer_config(config, args) update_file_writer_config(config, args)
update_scene_config(config, args) update_scene_config(config, args)
update_run_config(config, args) update_run_config(config, args)
update_embed_config(config, args)
return Dict(config) return Dict(config)
@ -209,6 +210,12 @@ def parse_cli():
"--log-level", "--log-level",
help="Level of messages to Display, can be DEBUG / INFO / WARNING / ERROR / CRITICAL" help="Level of messages to Display, can be DEBUG / INFO / WARNING / ERROR / CRITICAL"
) )
parser.add_argument(
"--autoreload",
action="store_true",
help="Automatically reload Python modules to pick up code changes " +
"across different files",
)
args = parser.parse_args() args = parser.parse_args()
args.write_file = any([args.write_file, args.open, args.finder]) args.write_file = any([args.write_file, args.open, args.finder])
return args return args
@ -311,6 +318,11 @@ def update_run_config(config: dict, args: Namespace):
) )
def update_embed_config(config: dict, args: Namespace):
if args.autoreload:
config["embed"]["autoreload"] = True
# Helpers for the functions above # Helpers for the functions above

View file

@ -83,6 +83,7 @@ text:
alignment: "LEFT" alignment: "LEFT"
embed: embed:
exception_mode: "Verbose" exception_mode: "Verbose"
autoreload: False
resolution_options: resolution_options:
# When the user passes in -l, -m, --hd or --uhd, these are the corresponding # When the user passes in -l, -m, --hd or --uhd, these are the corresponding
# resolutions # resolutions

View file

@ -29,6 +29,8 @@ class InteractiveSceneEmbed:
self.enable_gui() self.enable_gui()
self.ensure_frame_update_post_cell() self.ensure_frame_update_post_cell()
self.ensure_flash_on_error() self.ensure_flash_on_error()
if manim_config.embed.autoreload:
self.auto_reload()
def launch(self): def launch(self):
self.shell() self.shell()
@ -139,6 +141,11 @@ class InteractiveSceneEmbed:
print("Reloading...") print("Reloading...")
self.shell.run_line_magic("exit_raise", "") self.shell.run_line_magic("exit_raise", "")
def auto_reload(self):
"""Enables IPython autoreload for automatic reloading of modules."""
self.shell.magic("load_ext autoreload")
self.shell.magic("autoreload all")
def checkpoint_paste( def checkpoint_paste(
self, self,
skip: bool = False, skip: bool = False,