fix: resolve ${KICAD_3RD_PARTY} (no version prefix) in lib URI resolvers (#187)

The Import-LIB-KiCad-Plugin documentation registers third-party libraries
using `${KICAD_3RD_PARTY}` (without a KiCad-version prefix). KiCad accepts
both unprefixed and version-prefixed forms in lib-tables, and the analogous
`KICAD_SYMBOL_DIR` was already handled in `library_symbol.py`'s env-var
dictionary.

`KICAD_3RD_PARTY` was missing from both `_resolve_uri` env-var dictionaries
(in `python/commands/library.py` and `python/commands/library_symbol.py`),
so lib-table rows authored as `${KICAD_3RD_PARTY}/Foo.kicad_sym` or
`${KICAD_3RD_PARTY}/Foo.pretty` failed to substitute, were treated as
non-existent paths, and disappeared from `list_symbol_libraries` /
`list_libraries` results — even though KiCad's GUI showed them correctly.

Changes:
  - Add `KICAD_3RD_PARTY` to both `_resolve_uri` env-var dictionaries.
  - Add `KICAD_3RD_PARTY` fallback in
    `SymbolLibraryManager._find_3rd_party_dir`.
  - Refactor `LibraryManager._find_kicad_3rdparty_dir` to check all four
    env-var forms (KICAD10/9/8_3RD_PARTY + KICAD_3RD_PARTY) consistently.
  - Add regression tests in `tests/test_kicad_3rd_party_env_resolution.py`.

Reproduces with:
  - Set `KICAD_3RD_PARTY` env var in the MCP server's environment.
  - Register `(lib (name "Foo") (type "KiCad") (uri "\${KICAD_3RD_PARTY}/Foo.kicad_sym") ...)` in the global sym-lib-table.
  - Place a real `Foo.kicad_sym` at the resolved path.
  - Before: `list_symbol_libraries` does not return `Foo`.
  - After: `Foo` is listed.
This commit is contained in:
gsdali
2026-05-19 13:19:50 +10:00
committed by GitHub
parent e2941631c1
commit 95e23c70ff
3 changed files with 84 additions and 4 deletions

View File

@@ -145,6 +145,7 @@ class LibraryManager:
"KICAD10_3RD_PARTY": self._find_kicad_3rdparty_dir(),
"KICAD9_3RD_PARTY": self._find_kicad_3rdparty_dir(),
"KICAD8_3RD_PARTY": self._find_kicad_3rdparty_dir(),
"KICAD_3RD_PARTY": self._find_kicad_3rdparty_dir(),
}
# Project directory
@@ -205,10 +206,11 @@ class LibraryManager:
import json
# 1. Check shell environment variable first
if "KICAD9_3RD_PARTY" in os.environ:
path = os.environ["KICAD9_3RD_PARTY"]
if os.path.isdir(path):
return path
for var in ("KICAD10_3RD_PARTY", "KICAD9_3RD_PARTY", "KICAD8_3RD_PARTY", "KICAD_3RD_PARTY"):
if var in os.environ:
path = os.environ[var]
if os.path.isdir(path):
return path
# 2. Check kicad_common.json for user-defined variables
kicad_common_paths = [