fix: pass __file__ to exec() in addon Init.py/InitGui.py loading #237
Reference in New Issue
Block a user
Delete Branch "fix/addon-init-file-variable"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Problem
DirMod.run_init() and DirModGui.run_init_gui() use exec(code) to run addon Init.py and InitGui.py files, but don't pass file in the globals dict. Addons that reference file (e.g. Silo) crash with:
Fix
Pass {"file": str(init_py)} as the globals argument to exec() so file is available in the executed code, matching the behavior of normal Python module loading.
Files Changed
DirMod.run_init() and DirModGui.run_init_gui() use exec(code) to run addon Init.py and InitGui.py files, but don't pass __file__ in the globals dict. Addons that reference __file__ (e.g. Silo) crash with NameError: name '__file__' is not defined. Pass {"__file__": str(init_py)} as the globals argument so __file__ is available in the executed code, matching the behavior of normal Python module loading.