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
Owner

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:

NameError: name '__file__' is not defined

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

  • src/App/FreeCADInit.py:1207 — DirMod.run_init()
  • src/Gui/FreeCADGuiInit.py:298 — DirModGui.run_init_gui()
## 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: NameError: name '__file__' is not defined ## 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 - src/App/FreeCADInit.py:1207 — DirMod.run_init() - src/Gui/FreeCADGuiInit.py:298 — DirModGui.run_init_gui()
forbes added 1 commit 2026-02-15 03:28:11 +00:00
fix: pass __file__ to exec() in addon Init.py/InitGui.py loading
Some checks failed
Build and Test / build (pull_request) Has been cancelled
e10841a6c8
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.
forbes merged commit 3de92325a3 into main 2026-02-15 03:28:28 +00:00
forbes deleted branch fix/addon-init-file-variable 2026-02-15 03:28:29 +00:00
Sign in to join this conversation.
No Reviewers
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: kindred/create#237