Skip to content

fix(setup): detect KiCAD on any drive and pin bundled Python for v10 - #356

Open
LiJoeAllen wants to merge 2 commits into
mixelpixx:mainfrom
LiJoeAllen:main
Open

fix(setup): detect KiCAD on any drive and pin bundled Python for v10#356
LiJoeAllen wants to merge 2 commits into
mixelpixx:mainfrom
LiJoeAllen:main

Conversation

@LiJoeAllen

Copy link
Copy Markdown

Fixes two issues with the Windows setup scripts for KiCAD 10:

  1. KiCAD detection no longer assumes C: drive. All-users installs can land on any drive; detection now queries registry uninstall keys (InstallLocation/DisplayIcon) and KICAD*_* environment variables before falling back to the standard paths.

  2. KiCAD 10 must use the bundled python from its install directory. Generated MCP configs now set KICAD_PYTHON to the detected bin\python.exe, and site-packages falls back to bin\Lib\site-packages when lib\python3\dist-packages is absent (the KiCad 10 layout).

Verified on a machine with KiCAD 10.0 at D:\Program Files\KiCad (detected via registry, pcbnew import works).

- Find KiCAD via registry uninstall keys (InstallLocation/DisplayIcon)
  and KICAD*_* environment variables, so installs outside C: drive
  (e.g. D:\Program Files\KiCad) are found for all-users setups
- Fall back to bin\Lib\site-packages when lib\python3\dist-packages
  is missing (KiCad 10 uses the bin layout)
- Set KICAD_PYTHON in generated MCP configs so KiCad 10 always uses
  the bundled python.exe from the install directory
@LiJoeAllen

Copy link
Copy Markdown
Author

@mixelpixx

@mixelpixx

Copy link
Copy Markdown
Owner

Reviewed — the approach is sound, and most of it back-ports detection logic that setup-windows-opencode.ps1 already has (its Get-KiCadInfo at line 187 has the same dist-packages -> site-packages fallback), so the pattern is established in-repo. The registry enumeration order (HKLM, WOW6432Node, HKCU, then KICAD*_* env vars, then the Program Files list) is right. And you incidentally fixed a real latent bug: the original $possiblePaths array was missing a comma after the (x86) entry, masked by PowerShell's newline separation.

Three concrete changes:

  1. DisplayIcon handling walks one level short: for a typical icon path D:...\KiCad\10.0\bin\kicad.exe, Split-Path -Parent yields ...\10.0\bin, and Get-KiCadInfo then probes ...\10.0\bin\bin\python.exe and misses. Walk up once more when the leaf is 'bin'.
  2. $script:KnownVersions is assigned inside Find-KiCAD but consumed by Get-KiCadInfo defined above it — works because PowerShell resolves at call time, but hoist it to a script-scope constant so the coupling is visible.
  3. The new setup-windows.ps1 Get-KiCadInfo omits the bin\Python.exe case-variant candidate the opencode version has. Make the two identical — or better, factor one shared helper so they cannot drift again.

Verification is necessarily anecdotal for setup scripts (CI has no D: drive); with the three items fixed I am comfortable merging on your D:-install evidence plus a re-test on a stock C: install.

LiJoeAllen added a commit to LiJoeAllen/KiCAD-MCP-Server that referenced this pull request Aug 21, 2026
…inning

Address maintainer review on PR mixelpixx#356:
- Walk up one level from the DisplayIcon bin directory so <root>\bin\kicad.exe resolves to the version root instead of probing <root>\bin\bin\python.exe (both scripts)
- Hoist $script:KnownVersions to script scope so Get-KiCadInfo does not depend on Find-KiCAD having run first
- Add the bin\Python.exe case-variant candidate to setup-windows.ps1 Get-KiCadInfo so probing matches setup-windows-opencode.ps1, with cross-reference comments in both
LiJoeAllen added a commit to LiJoeAllen/KiCAD-MCP-Server that referenced this pull request Aug 21, 2026
…inning

Address maintainer review on PR mixelpixx#356:
- Walk up one level from the DisplayIcon bin directory so <root>\bin\kicad.exe resolves to the version root instead of probing <root>\bin\bin\python.exe (both scripts)
- Hoist $script:KnownVersions to script scope so Get-KiCadInfo does not depend on Find-KiCAD having run first
- Add the bin\Python.exe case-variant candidate to setup-windows.ps1 Get-KiCadInfo so probing matches setup-windows-opencode.ps1, with cross-reference comments in both
…inning

Address maintainer review on PR mixelpixx#356:
- Walk up one level from the DisplayIcon bin directory so <root>\bin\kicad.exe resolves to the version root instead of probing <root>\bin\bin\python.exe (both scripts)
- Hoist $script:KnownVersions to script scope so Get-KiCadInfo does not depend on Find-KiCAD having run first
- Add the bin\Python.exe case-variant candidate to setup-windows.ps1 Get-KiCadInfo so probing matches setup-windows-opencode.ps1, with cross-reference comments in both
@LiJoeAllen

Copy link
Copy Markdown
Author

Thanks for the thorough review - all three items are addressed in a30be1a:

  1. DisplayIcon walk-up - both scripts now walk up one level when the icon
    directory leaf is bin, so <root>\10.0\bin\kicad.exe resolves to
    <root>\10.0 instead of probing <root>\10.0\bin\bin\python.exe.
  2. KnownVersions hoist - $script:KnownVersions is now a script-scope
    constant defined next to Get-KiCadInfo, not assigned inside Find-KiCAD,
    so the coupling is visible at the top of the file.
  3. Probing parity - setup-windows.ps1's Get-KiCadInfo now probes both
    bin\python.exe and bin\Python.exe exactly like the opencode script, and
    each file carries a comment pointing at the sibling script so the probing
    logic cannot silently drift. I kept the two scripts standalone (each is
    distributed and run as a single file) rather than factoring a shared
    dot-sourced module; the probe logic itself is now identical.

Verification:

  • Real D: install (KiCad Huaqiu 10.0; registry InstallLocation =
    D:\Program Files\KiCad\10.0; DisplayIcon = <...>\bin/kicad.exe,0):
    Find-KiCAD resolves it, and Get-KiCadInfo returns
    bin\Lib\site-packages (the KiCad 10 layout; lib\python3\dist-packages is
    absent here).
  • Icon walk-up: the real ,0-suffixed icon path and a simulated layout both
    resolve to the version root and locate bin\python.exe.
  • Simulated stock layout (bare root + 10.0\bin\python.exe +
    bin\Lib\site-packages): detected with the same site-packages fallback.
  • Both scripts parse clean via the PowerShell AST parser (no syntax errors).

I can't spin up a real C: install on this machine, but the simulated layout
above covers the stock shape; happy to re-run on one before merging if you'd
like.

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