app
KiCad - the KiCad Bridge
Public Made by Adomby adom
Reference implementation of the KiCad bridge: multi-instance Python server, forward path via kicad-cli, reverse path via in-process plugin. Most complex of the three bundled bridges.
← Commit history
0.9.341: Release-day fixes: stock library path resolution (#80), screenshot_all sizeKB (#81), readiness re-detect (#82), routing DRC completeness (PR 82), verified source pushes (#79), full verb-test coverage (#78)
4 files changed
+50−7
BRIDGE_VERSION+1−1@@ -1 +1 @@-0.9.340+0.9.341
adom_library.py+44−4@@ -85,15 +85,55 @@ def _get_paths(kicad_info: dict) -> tuple[Path, Path] | None: return table_path, lib_path +def _kicad_env_overrides(kicad_info: dict) -> dict:+ """Path variables the user overrode in Preferences > Configure Paths+ (kicad_common.json "environment.vars"). Those win over the defaults."""+ import json as _json+ import os as _os+ ver = str(kicad_info.get("version") or "")+ roots = []+ if _os.environ.get("APPDATA"):+ roots.append(Path(_os.environ["APPDATA"]) / "kicad")+ roots.append(Path.home() / "Library" / "Preferences" / "kicad")+ roots.append(Path(_os.environ.get("XDG_CONFIG_HOME") or Path.home() / ".config") / "kicad")+ for root in roots:+ cand = root / ver / "kicad_common.json" if ver else None+ if cand and cand.is_file():+ try:+ env = _json.loads(cand.read_text(encoding="utf-8")).get("environment") or {}+ vars_ = env.get("vars") or {}+ return {k: str(v) for k, v in vars_.items() if isinstance(v, str) and v}+ except Exception:+ return {}+ return {}++ def _expand_kicad_uri(uri: str, kicad_info: dict) -> str | None:- """Expand the path variables a sym-lib-table uri may carry. Only the ones- the bridge itself would have written or KiCad seeds by default."""+ """Expand the path variables a sym-lib-table / fp-lib-table uri may carry.++ KICAD<n>_SYMBOL_DIR, _FOOTPRINT_DIR and _3DMODEL_DIR are KiCad's STOCK+ libraries under <install>/share/kicad (issue #80: they were wrongly mapped+ to the user's Documents folder, so kicad_list_symbols {"libraryName":"Device"}+ reported a missing library on every box). A user override from Configure+ Paths wins. KIPRJMOD is project-relative and refused; unknown variables+ are refused rather than guessed.""" import os as _os ver = str(kicad_info.get("version") or "") major = ver.split(".")[0] if ver else "" subs = {}- if kicad_info.get("user_dir"):- subs[f"KICAD{major}_SYMBOL_DIR"] = str(Path(kicad_info["user_dir"]) / "symbols")+ base = kicad_info.get("base_dir")+ if base:+ share = Path(base) / "share" / "kicad"+ subs[f"KICAD{major}_SYMBOL_DIR"] = str(share / "symbols")+ subs[f"KICAD{major}_FOOTPRINT_DIR"] = str(share / "footprints")+ subs[f"KICAD{major}_3DMODEL_DIR"] = str(share / "3dmodels")+ subs[f"KICAD{major}_TEMPLATE_DIR"] = str(share / "template")+ docs = kicad_info.get("user_dir")+ if docs:+ subs["KICAD_USER_TEMPLATE_DIR"] = str(Path(docs) / "template")+ if _os.environ.get("APPDATA") and ver:+ subs["KICAD_3RD_PARTY"] = str(Path(_os.environ["APPDATA"]) / "kicad" / ver / "3rdparty")+ subs.update(_kicad_env_overrides(kicad_info)) subs["KIPRJMOD"] = None # project-relative: not a global library, refuse out = uri.replace("\\", "/") for k, v in subs.items():
bridge.json+1−1@@ -2,7 +2,7 @@ "manifest_version": 1, "name": "kicad", "displayName": "KiCad EDA",- "version": "0.9.340",+ "version": "0.9.341", "description": "Reverse bridge for KiCad \u2014 board/schematic introspection, lint via kicad-cli, plugin install, multi-instance probe, in-process DRC.", "homepage": "https://wiki.adom.inc/adom/adom-bridge", "author": "Adom Inc.",
handlers/kicad_ui.py+4−1@@ -840,7 +840,10 @@ def handle_screenshot_all(kicad_info: dict, args: dict) -> dict: if result.get("success"): entry["savedTo"] = result["savedTo"] entry["fullPath"] = result.get("fullPath", result["savedTo"])- entry["sizeKB"] = result["sizeKB"]+ if result.get("sizeKB") is not None:+ entry["sizeKB"] = result["sizeKB"]+ if result.get("capturedBy"):+ entry["capturedBy"] = result["capturedBy"] else: entry["error"] = result.get("error", "screenshot failed")