Repository navigation
refactor(gcode): read G-code into the Motion IR at the CLI/API boundary (S-bnd) - #283
Merged
Merged
Conversation
Introduce `read_program` — the single G-code text->Program adapter and the
inverse of `serialize` — so the simulator and plotter consume the typed Motion
IR instead of each re-parsing text. The CLI `simulate`/`plot` commands and the
`/simulate`+`/plot` routes parse once at the boundary; the external-`.gcode`
use case and the GUI `{gcode}->/plot` path are unchanged.
This slice is deliberately output-preserving: both consumers reproduce today's
numbers exactly (the simulator stays G92-blind, marked `minimal:` for S3; the
plotter is unchanged), so `sim_plot_snapshot.json` stays green without regen —
the proof that the reader is faithful, mirroring #274's empty-diff gate. The
new `test_reader_roundtrip` confirms `serialize(read_program(g)) == g`
byte-for-byte on all seven frozen goldens. The two `_detect_dialect` copies and
the plotter's `ast.literal_eval` header parse collapse into the reader.
The deliberate metric deltas (G92-aware time, O1 unification) follow as isolated
regens in S3 (simulator shares nominal_metrics) and S4 (plotter geometry).
Closes #282. Part of #136.
This was referenced Jun 28, 2026
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.
S-bnd of #136 — closes #282.
Introduces
fiberpath/gcode/reader.py::read_program, the single G-code text→Programadapter (inverse ofserialize). The simulator and plotter now consume the typed Motion IR; the CLIsimulate/plotand the/simulate+/plotroutes parse once at the boundary. The two duplicated_detect_dialectcopies and the plotter'sast.literal_evalheader parse collapse into the reader —read_programis the only G-code text parser left (verifiable by grep).Output-preserving by design
Both consumers reproduce today's numbers exactly (the simulator stays G92-blind — marked
minimal:for S3; the plotter is unchanged), so the gate is a greensim_plot_snapshot.jsonwith no regen — the proof the reader is faithful, mirroring #274's empty-diff gate. The deliberate metric deltas (G92-aware time, O1 unification) land next as isolated regens in S3 (simulator sharesnominal_metrics) and S4 (plotter geometry).Acceptance — all green
tests/gcode/test_reader_roundtrip.py:serialize(read_program(g)) == gbyte-for-byte on all 7 frozen goldens + unit tests (header, comment, G92, feed, mixed feed+motion, XYZ rejection).test_example_goldensbyte-equal (untouched) ·sim_plot_snapshot.jsongreen withoutFIBERPATH_UPDATE_GOLDENS.{gcode}→/plotunaffected.Part of #136. Followed by S3 (simulator), S4 (plotter), S5 (delete dead parsers + CI guard).