Skip to content

Skip KiCad plugin registration when run with python -m - #587

Merged
qu1ck merged 1 commit into
openscopeproject:masterfrom
DominikPalo:fix-cli-module-without-pcbnew
Oct 6, 2026
Merged

qu1ck merged 1 commit into
openscopeproject:masterfrom
DominikPalo:fix-cli-module-without-pcbnew

Conversation

@DominikPalo

Copy link
Copy Markdown
Contributor

InteractiveHtmlBom/__init__.py registers the pcbnew action plugin, which imports .ecad.kicad and therefore pcbnew, unless INTERACTIVE_HTML_BOM_CLI_MODE is set or os.path.basename(sys.argv[0]) starts with generate_interactive_bom.

When the CLI is started as a module:

python -m InteractiveHtmlBom.generate_interactive_bom board.brd

Python sets sys.argv[0] to '-m' while it locates the module, which is when the package __init__ runs. It only replaces it with the module's file path afterwards. The filename check never matches, so on a system without KiCad the command fails before doing anything:

  File ".../InteractiveHtmlBom/ecad/kicad.py", line 4, in <module>
    import pcbnew
ModuleNotFoundError: No module named 'pcbnew'

This breaks python -m usage for EasyEDA, Eagle/Fusion and generic JSON inputs unless users know to set INTERACTIVE_HTML_BOM_CLI_MODE. The fix also skips registration when sys.argv[0] == '-m'. KiCad never loads plugins via -m, so plugin loading in pcbnew is unaffected.

Testing

Without INTERACTIVE_HTML_BOM_CLI_MODE set:

Invocation master this PR
python3 -m InteractiveHtmlBom.generate_interactive_bom board.brd (no pcbnew) ModuleNotFoundError: pcbnew BOM generated
python3 InteractiveHtmlBom/generate_interactive_bom.py board.brd (no pcbnew) works works (unchanged)
KiCad's bundled Python, -m ... board.kicad_pcb works works
KiCad's Python importing the package with sys.argv = ['pcbnew'] (simulated plugin load) plugin registered plugin registered (unchanged)

The simulated plugin load prints a PgmOrNull() assert from action_plugin.cpp on both master and this branch. That happens because there is no running KiCad app in the test, not because of this change. I have not tested plugin loading inside a running pcbnew.

🤖 Generated with Claude Code

The package __init__ registers the pcbnew action plugin unless
INTERACTIVE_HTML_BOM_CLI_MODE is set or argv[0] looks like the
generate_interactive_bom script. With
"python -m InteractiveHtmlBom.generate_interactive_bom" argv[0] is
still "-m" while the package is imported, so it imported .ecad.kicad
and failed with ModuleNotFoundError: pcbnew on systems without KiCad,
breaking CLI use for EasyEDA, Eagle/Fusion and generic JSON files.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@qu1ck
qu1ck merged commit e55914f into openscopeproject:master Oct 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants