Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Autoreload v2 #2268

Merged
merged 3 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/source/getting_started/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ flag abbr function
``--video_dir VIDEO_DIR`` Directory to write video
``--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
``--autoreload`` Automatically reload Python modules to pick up code changes across different files
========================================================== ====== =====================================================================================================================================================================================================

custom_config
Expand Down
12 changes: 12 additions & 0 deletions manimlib/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ def initialize_manim_config() -> Dict:
update_file_writer_config(config, args)
update_scene_config(config, args)
update_run_config(config, args)
update_embed_config(config, args)

return Dict(config)

Expand Down Expand Up @@ -209,6 +210,12 @@ def parse_cli():
"--log-level",
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.write_file = any([args.write_file, args.open, args.finder])
return args
Expand Down Expand Up @@ -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


Expand Down
1 change: 1 addition & 0 deletions manimlib/default_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ text:
alignment: "LEFT"
embed:
exception_mode: "Verbose"
autoreload: False
resolution_options:
# When the user passes in -l, -m, --hd or --uhd, these are the corresponding
# resolutions
Expand Down
7 changes: 7 additions & 0 deletions manimlib/scene/scene_embed.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ def __init__(self, scene: Scene):
self.enable_gui()
self.ensure_frame_update_post_cell()
self.ensure_flash_on_error()
if manim_config.embed.autoreload:
self.auto_reload()

def launch(self):
self.shell()
Expand Down Expand Up @@ -139,6 +141,11 @@ def reload_scene(self, embed_line: int | None = None) -> None:
print("Reloading...")
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(
self,
skip: bool = False,
Expand Down
Loading