Parse .kicad_pcb on a real s-expression parser (KiCad 5-10)#21
Open
prat96 wants to merge 1 commit into
Open
Conversation
The regex loader returned 0 nets/0 pads on KiCad 8/9/10 files (no net table; references in (property "Reference" ...)), so loading a board from a file was broken. Replace it with a dependency-free s-expression parser (sexpr.py) and a structural extractor (file_parser.py) handling every dialect through KiCad 10 (format 20260206): name-only net synthesis, footprint rotation and back-side pad transform (verified pad-exact vs pcbnew 10.0.4), Edge.Cuts excluded from the copper count, design rules merged from the sibling .kicad_pro. Tests use small self-contained synthetic boards (both dialects). Also: pad_escape_planner drill/drill_size fallback and rich_kicad_interface kipy import fix. Re-include tests/*.py (the .gitignore blocked the suite). Signed-off-by: Pratheek Balakrishna <pratheekb96@gmail.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.
What
Replaces the regex
.kicad_pcbloader with a real s-expression parser thatreads every KiCad dialect from 5 through 10.
Why
KiCad 8/9/10 dropped the numbered net table and moved references into
(property "Reference" ...). The old regex loader returns 0 nets / 0 padson those files, so loading a board directly from disk (the
cliand headlesspaths) is effectively broken on any modern board.
What's in it
sexpr.py— a small, dependency-free balanced-paren parser (Python 3.9clean) plus byte-exact, idempotent top-level strip helpers.
file_parser.py— structural pad/net/layer extraction across both dialects:legacy numbered-net +
(module ...), and modern net-table-free(footprint ...)/propertywith name-only(net "NAME")synthesis.Footprint rotation is CCW-positive in KiCad's Y-down frame and back-side pad
offsets carry no extra mirror — verified pad-exact (≤1 µm) against
pcbnew 10.0.4. Copper-layer counting excludes
Edge.Cuts; design rules aremerged from a sibling
.kicad_prowhen present.pad_escape_plannerreadsdrillwith adrill_sizefallback;rich_kicad_interfaceimportsKiCadfromkipy(matching the rest of the codebase).
Tests
Small, self-contained synthetic boards (no external board files):
test_sexpr— parser round-trips + idempotent strip helpers.test_file_parser— both dialects: legacy numbered-net(module ...), andmodern net-table-free
(footprint ...)/propertywith name-only netsynthesis, back-side pad placement, and
Edge.Cutsexclusion.Notes for review
first if you'd prefer — opened as a PR because the old path returns nothing
on current KiCad files, so it's arguably a bug fix.
real multi-layer boards (front/back, rot 0/90/180/270). The shipped tests pin
the same transform on synthetic boards so the suite stays fixture-free.
Checklist