Minor cleaning

This commit is contained in:
Grant Sanderson 2024-12-09 14:01:34 -06:00
parent 40b5c7c1c1
commit cb3e115a6c

View file

@ -33,19 +33,18 @@ def get_ipython_shell_for_embedded_scene(scene):
# Triple back should take us to the context in a user's scene definition # Triple back should take us to the context in a user's scene definition
# which is calling "self.embed" # which is calling "self.embed"
caller_frame = inspect.currentframe().f_back.f_back.f_back caller_frame = inspect.currentframe().f_back.f_back.f_back
# Update the module's namespace to include local variables
module = ModuleLoader.get_module(caller_frame.f_globals["__file__"]) module = ModuleLoader.get_module(caller_frame.f_globals["__file__"])
shell = InteractiveShellEmbed( module.__dict__.update(caller_frame.f_locals)
module.__dict__.update(get_shortcuts(scene))
return InteractiveShellEmbed(
user_module=module, user_module=module,
display_banner=False, display_banner=False,
xmode=scene.embed_exception_mode xmode=scene.embed_exception_mode
) )
# Update the module's namespace to match include local variables
module.__dict__.update(caller_frame.f_locals)
module.__dict__.update(get_shortcuts(scene))
return shell
def get_shortcuts(scene): def get_shortcuts(scene):
""" """
@ -130,9 +129,9 @@ class CheckpointManager:
@staticmethod @staticmethod
def handle_method_definitions(code_string: str): def handle_method_definitions(code_string: str):
lines = code_string.split("\n")
# Copied methods of a scene are handled specially # Copied methods of a scene are handled specially
# A bit hacky, yes, but convenient # A bit hacky, yes, but convenient
lines = code_string.split("\n")
method_pattern = r"^def\s+([a-zA-Z_]\w*)\s*\(self.*\):" method_pattern = r"^def\s+([a-zA-Z_]\w*)\s*\(self.*\):"
method_names = re.findall(method_pattern, lines[0].strip()) method_names = re.findall(method_pattern, lines[0].strip())
if method_names: if method_names: