Don't write new file when inserting embed line

Instead, load the relevant module of the true file, and execute the modified code within that.

This also cleans up some of the previous now-unnecessary code around get_module_with_inserted_embed_line
This commit is contained in:
Grant Sanderson
2024-12-06 11:05:57 -07:00
parent dd0aa14442
commit fadd045fc1
2 changed files with 15 additions and 35 deletions

View File

@ -76,10 +76,7 @@ class ModuleLoader:
builtins.__import__ = tracked_import
try:
# Remove the "_insert_embed" suffix from the module name
module_name = module.__name__
if module.__name__.endswith("_insert_embed"):
module_name = module_name[:-13]
log.debug('Reloading module "%s"', module_name)
spec.loader.exec_module(module)