fix: pass __file__ to exec() in addon Init.py/InitGui.py loading #237

Merged
forbes merged 1 commits from fix/addon-init-file-variable into main 2026-02-15 03:28:28 +00:00
2 changed files with 2 additions and 2 deletions

View File

@@ -1204,7 +1204,7 @@ class DirMod(Mod):
try:
source = init_py.read_text(encoding="utf-8")
code = compile(source, init_py, 'exec')
exec(code)
exec(code, {"__file__": str(init_py)})
except Exception as ex:
Log(f"Init: Initializing {self.path!s}... failed")
Log(utils.HLine)

View File

@@ -295,7 +295,7 @@ class DirModGui(ModGui):
try:
source = init_gui_py.read_text(encoding="utf-8")
code = compile(source, init_gui_py, "exec")
exec(code)
exec(code, {"__file__": str(init_gui_py)})
except Exception as ex:
sep = "-" * 100 + "\n"
Log(f"Init: Initializing {target!s}... failed\n")