mirror of
https://github.com/3b1b/manim.git
synced 2025-04-13 09:47:07 +00:00
Instantiate the IPython shell without a local ns
This commit is contained in:
parent
d4080b8978
commit
2dd0256af6
1 changed files with 10 additions and 13 deletions
|
@ -220,14 +220,14 @@ class Scene(object):
|
||||||
self.save_state()
|
self.save_state()
|
||||||
self.show_animation_progress = show_animation_progress
|
self.show_animation_progress = show_animation_progress
|
||||||
|
|
||||||
# Create embedded IPython terminal to be configured
|
# Create embedded IPython terminal configured to have access to
|
||||||
shell = InteractiveShellEmbed.instance()
|
# the local namespace of the caller
|
||||||
|
|
||||||
# Use the locals namespace of the caller
|
|
||||||
caller_frame = inspect.currentframe().f_back
|
caller_frame = inspect.currentframe().f_back
|
||||||
local_ns = dict(caller_frame.f_locals)
|
module = get_module(caller_frame.f_globals["__file__"])
|
||||||
|
shell = InteractiveShellEmbed(user_module=module)
|
||||||
|
|
||||||
# Add a few custom shortcuts
|
# Add a few custom shortcuts to that local namespace
|
||||||
|
local_ns = dict(caller_frame.f_locals)
|
||||||
local_ns.update(
|
local_ns.update(
|
||||||
play=self.play,
|
play=self.play,
|
||||||
wait=self.wait,
|
wait=self.wait,
|
||||||
|
@ -244,6 +244,9 @@ class Scene(object):
|
||||||
notouch=lambda: shell.enable_gui(None),
|
notouch=lambda: shell.enable_gui(None),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Update the shell module with the caller's locals + shortcuts
|
||||||
|
module.__dict__.update(local_ns)
|
||||||
|
|
||||||
# Enables gui interactions during the embed
|
# Enables gui interactions during the embed
|
||||||
def inputhook(context):
|
def inputhook(context):
|
||||||
while not context.input_is_ready():
|
while not context.input_is_ready():
|
||||||
|
@ -278,13 +281,7 @@ class Scene(object):
|
||||||
shell.magic(f"xmode {self.embed_exception_mode}")
|
shell.magic(f"xmode {self.embed_exception_mode}")
|
||||||
|
|
||||||
# Launch shell
|
# Launch shell
|
||||||
shell(
|
shell()
|
||||||
local_ns=local_ns,
|
|
||||||
# Pretend like we're embeding in the caller function, not here
|
|
||||||
stack_depth=2,
|
|
||||||
# Specify that the present module is the caller's, not here
|
|
||||||
module=get_module(caller_frame.f_globals["__file__"])
|
|
||||||
)
|
|
||||||
|
|
||||||
# End scene when exiting an embed
|
# End scene when exiting an embed
|
||||||
if close_scene_on_exit:
|
if close_scene_on_exit:
|
||||||
|
|
Loading…
Add table
Reference in a new issue