From 2e433fcd0d1afadd8ab786dd30d7d4546bdee43d Mon Sep 17 00:00:00 2001 From: Louis Date: Wed, 11 Nov 2026 10:08:41 +0100 Subject: hw-toolchain: placer, routers and KiCad helpers for agent-driven hardware work Rust placer (simulated annealing) and negotiated-congestion router for 2-layer KiCad boards, pnr.sh to place, route, DRC-check and install candidates, Python KiCad helpers, repo conventions (AGENTS.md) and the tool documentation under knowledge/. Konnect (KiCad MCP, AGPL) as a submodule. Co-Authored-By: Claude Opus 5.5 --- tools/kicad_paths.py | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 tools/kicad_paths.py (limited to 'tools/kicad_paths.py') diff --git a/tools/kicad_paths.py b/tools/kicad_paths.py new file mode 100644 index 0000000..2f46052 --- /dev/null +++ b/tools/kicad_paths.py @@ -0,0 +1,55 @@ +"""Where things live: the hardware repo root and KiCad's stock libraries. + +ROOT is the hardware repo the tools work on, the directory that holds libraries/ (your HW +symbol, footprint and 3D model libraries). It is HW_ROOT if set, else the nearest directory +at or above the current one that has a libraries/ folder, else the parent of tools/. + +KiCad's own environment variables win (KICAD10_SYMBOL_DIR, KICAD10_FOOTPRINT_DIR, +KICAD10_3DMODEL_DIR), then KICAD_SHARE (the directory that holds symbols/, footprints/, +3dmodels/), then the usual install locations on macOS, Linux and Windows. + + from kicad_paths import ROOT, SYMBOLS, FOOTPRINTS, MODELS3D +""" +import os + + +def repo_root(): + env = os.environ.get("HW_ROOT") + if env: + return os.path.abspath(env) + d = os.getcwd() + while True: + if os.path.isdir(os.path.join(d, "libraries")): + return d + up = os.path.dirname(d) + if up == d: + break + d = up + return os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + + +ROOT = repo_root() + +_CANDIDATES = [ + "/Applications/KiCad/KiCad.app/Contents/SharedSupport", # macOS + "/usr/share/kicad", # Linux packages + "/usr/local/share/kicad", + "/app/share/kicad", # Flatpak + r"C:\Program Files\KiCad\10.0\share\kicad", # Windows +] + + +def share_dir(): + env = os.environ.get("KICAD_SHARE") + if env: + return env + for c in _CANDIDATES: + if os.path.isdir(os.path.join(c, "footprints")) or os.path.isdir(os.path.join(c, "symbols")): + return c + return _CANDIDATES[0] + + +SHARE = share_dir() +SYMBOLS = os.environ.get("KICAD10_SYMBOL_DIR") or os.path.join(SHARE, "symbols") +FOOTPRINTS = os.environ.get("KICAD10_FOOTPRINT_DIR") or os.path.join(SHARE, "footprints") +MODELS3D = os.environ.get("KICAD10_3DMODEL_DIR") or os.path.join(SHARE, "3dmodels") -- cgit v1.3