[framework] bench2 edit — one-command live editing in CQ-editor - #67
Open
BenchCAD wants to merge 3 commits into
Open
[framework] bench2 edit — one-command live editing in CQ-editor#67BenchCAD wants to merge 3 commits into
BenchCAD wants to merge 3 commits into
Conversation
`uv run bench2 edit <family>` opens the family's part.py in CQ-editor with the part already on screen, and leaves the file clean afterwards: 1. installs CQ-editor on first use (new `editor` dependency group), so there is no separate 'uv tool install' step; 2. samples a valid instance (honouring spec.check, with k=v overrides) and appends a marked scratch block — PARAMS + show_object(build(**PARAMS)); 3. launches the editor and waits; F5 re-renders what you type; 4. strips the scratch block when the editor closes, keeping your edits. The editor runs INSIDE the project env, which is the point: it uses the pinned cadquery 2.3.0 and can import bench2, so geomlib families render exactly as bench2 validate builds them. A stand-alone `uv tool install cq-editor` brings cadquery 2.8 and cannot import bench2 — that was the old, documented limitation. The launcher also applies the OCP HashCode shim before cq_editor imports cadquery (pinned 2.3.0 + OCP 7.9 dropped TopoDS_*.HashCode). Belt and braces: if the editor is killed, the block survives — so `bench2 validate` now fails with 'part.py still has a bench2 edit scratch block' and `bench2 edit <family> --strip` removes it. Verified on designs/slotted_din_rail + speaker_pole_mount_socket: the editor window opens and stays up, cq_editor's own make_AIS() converts build()'s result (AIS_Shape, correct bbox) under cadquery 2.3.0, the block round-trips byte-identically, validate goes red then green, and ruff is clean. Signed-off-by: BenchCAD <benchcad@users.noreply.github.com>
bench2 validateslotted_din_railspeaker_pole_mount_socketPreviews: the |
HaozheZhang6
self-requested a review
July 28, 2026 09:26
HaozheZhang6
requested changes
Jul 28, 2026
HaozheZhang6
left a comment
Collaborator
There was a problem hiding this comment.
Ran the whole thing on a fresh clone on this machine (macOS arm64, py3.11) rather than taking the Verified list on faith:
uv run bench2 edit slotted_din_rail --diff hard --seed 3— first run installed the editor group (43 pkgs, well under a minute with a warm uv cache), appended the scratch block with a valid sampled instance, and the CQ-editor window came up and stayed up in the pinned env (cadquery 2.3.0, HashCode shim active — no OCP crash on boot).- Close path: block auto-removed,
part.pybyte-identical afterwards (git diffempty). - Crash path:
kill -9on the whole tree → block survives →bench2 validatefails with the exact--strippointer →--strip→ validate PASS, file byte-identical again.
One thing I could not verify without driving the GUI: whether the part is drawn on open ("with the part already on screen") or only after the first F5 — worth a one-word tweak if it's the latter.
Two asks:
- Drop the "Generated with Claude Code" footer from the PR body (and keep it out of the squash message) — repo convention is no AI attribution anywhere; the commits themselves are clean.
bench2 edit --file <path> k=vsilently swallows the first override into the unusedfamilypositional. Cheap fix: error (or warn) when both--fileand a bare positional are given.
Minor, non-blocking: strip_block on a LEGACY_MARK block deletes everything after the mark (no end sentinel) — fine for appended blocks, would eat trailing code if someone hand-moved one mid-file.
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.
uv run bench2 edit <family>— open a family'spart.pyin CQ-editor with the part already on screen, edit, press F5, close. That's the whole workflow; there is no install step.Why
Today live editing means:
uv tool install cq-editor(manual, one-time), thenuv run python tools/debug_family.py --config designs/<fam>/part.py, then remember--stripbefore committing. And that stand-alone editor brings cadquery 2.8 and cannotimport bench2, so it disagrees with whatbench2 validatebuilds and simply fails on families that usebench2.geomlibhelpers — our own docs told people to use ocp-vscode instead.What
bench2 editdoeseditordependency group,uv run --group editor, ~1 min, cached afterwards);spec.check;--diff,--seed,k=voverrides) and appends a marked scratch block topart.py— thePARAMSdict plus theshow_object(build(**PARAMS))call CQ-editor needs to draw anything;part.pyreturns to the cleanbuild()the benchmark derives from.Running inside the project env is the point: the editor uses the pinned cadquery 2.3.0 and can
import bench2, so a geomlib family renders exactly asbench2 validatewill build it. The launcher also applies the OCPHashCodeshim beforecq_editorimports cadquery (2.3.0 + OCP 7.9 droppedTopoDS_*.HashCode).Belt and braces
If the editor is killed the block survives, so
bench2 validatenow fails with "part.py still has abench2 editscratch block" and points atbench2 edit <family> --strip. A leftover block used to be silently committable (show_objectis stubbed inexecute.py).Verified
cadquery 2.3.0,cq-editor 0.7.0, py3.11);show_objectinjected and pushing the result through cq-editor's ownmake_AIS()gives anAIS_Shapewith the right bbox (600 × 35 × 7.5 mm forslotted_din_railhard) — i.e. cadquery 2.3.0 drives the editor's viewer fine;git diffclean after close);bench2 validatered with a block, green after--strip; both merged families still PASS;ruffclean on the changed files.Notes
docs/DEBUGGING.md§A rewritten aroundbench2 edit; the old "CQ-editor runs cadquery 2.8, prefer ocp-vscode" gotcha is no longer true and is replaced.tools/debug_family.pykeeps its no-GUI "print params/check/solids/bbox" mode (still handy, still used by WALKTHROUGH); its docstring now points GUI users atbench2 edit.uv.lockgrows by theeditorgroup (PyQt5 + qtconsole). It is not a default group:uv syncand CI don't download it.🤖 Generated with Claude Code