From 39fbb677dcc86fc32075249e66a3cbaba508aa7b Mon Sep 17 00:00:00 2001 From: Grant Sanderson Date: Fri, 13 Dec 2024 15:23:50 -0600 Subject: [PATCH] Have autoreload update shell namespace with reloaded module variables (#2278) * Have autoreload update shell namespace with reloaded module variables * Update comments --- docs/source/getting_started/configuration.rst | 2 +- manimlib/scene/scene_embed.py | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/docs/source/getting_started/configuration.rst b/docs/source/getting_started/configuration.rst index 47e1a2e8..465203c6 100644 --- a/docs/source/getting_started/configuration.rst +++ b/docs/source/getting_started/configuration.rst @@ -63,7 +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 +``--autoreload`` Automatically reload Python modules to pick up code changes across during an interactive embedding ========================================================== ====== ===================================================================================================================================================================================================== custom_config diff --git a/manimlib/scene/scene_embed.py b/manimlib/scene/scene_embed.py index 1df79597..429693dd 100644 --- a/manimlib/scene/scene_embed.py +++ b/manimlib/scene/scene_embed.py @@ -142,9 +142,12 @@ class InteractiveSceneEmbed: 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") + """Enables reload the shell's module before all calls""" + def pre_cell_func(*args, **kwargs): + new_mod = ModuleLoader.get_module(self.shell.user_module.__file__, is_during_reload=True) + self.shell.user_ns.update(vars(new_mod)) + + self.shell.events.register("pre_run_cell", pre_cell_func) def checkpoint_paste( self,