Repository navigation
Skip KiCad plugin registration when run with python -m - #587
Merged
qu1ck merged 1 commit intoOct 6, 2026
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
InteractiveHtmlBom/__init__.pyregisters the pcbnew action plugin, which imports.ecad.kicadand thereforepcbnew, unlessINTERACTIVE_HTML_BOM_CLI_MODEis set oros.path.basename(sys.argv[0])starts withgenerate_interactive_bom.When the CLI is started as a module:
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:This breaks
python -musage for EasyEDA, Eagle/Fusion and generic JSON inputs unless users know to setINTERACTIVE_HTML_BOM_CLI_MODE. The fix also skips registration whensys.argv[0] == '-m'. KiCad never loads plugins via-m, so plugin loading in pcbnew is unaffected.Testing
Without
INTERACTIVE_HTML_BOM_CLI_MODEset:python3 -m InteractiveHtmlBom.generate_interactive_bom board.brd(no pcbnew)ModuleNotFoundError: pcbnewpython3 InteractiveHtmlBom/generate_interactive_bom.py board.brd(no pcbnew)-m ... board.kicad_pcbsys.argv = ['pcbnew'](simulated plugin load)The simulated plugin load prints a
PgmOrNull()assert fromaction_plugin.cppon 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