feat(cli): add --overwrite/--no-overwrite output safety to all output commands#970
Open
xieofxie wants to merge 3 commits into
Open
feat(cli): add --overwrite/--no-overwrite output safety to all output commands#970xieofxie wants to merge 3 commits into
xieofxie wants to merge 3 commits into
Conversation
… commands
Output-producing commands silently clobbered an existing file/dir on a
re-run, with no warning, prompt, or opt-in. Add a shared safe-overwrite
control (default: refuse and error) so a re-run can't destroy a prior result.
Shared helpers in utils/cli.py:
- overwrite_option(): --overwrite/--no-overwrite toggle, default no-overwrite.
- guard_output(path, overwrite): fail-fast existence check. Files block when
they exist; directories block only when non-empty (so a fresh/empty output
dir doesn't false-trigger). None path (stdout) is a no-op.
Wired into export, optimize, quantize, compile, config, eval, analyze, perf,
catalog, run. The guard runs before any mkdir/cleanup/work (e.g. before the
quantizer's destructive stale-sidecar unlink) and covers default-derived
output paths (e.g. {stem}_qdq.onnx), not just explicit -o.
build is intentionally excluded: it already has --rebuild plus incremental
resume (existing stage artifacts are reused, not clobbered), so a non-empty
output-dir guard there would break legitimate incremental rebuilds.
Fixes #561
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.
Summary
Output-producing commands silently overwrote an existing file/dir on a re-run — no warning, no prompt, no opt-in (#561). This adds a shared safe-overwrite control so a re-run can't destroy a previous result.
Flag name
Chose
--overwrite/--no-overwrite(default--no-overwrite) over the issue body's--force/-fbecause it matches the dominant--x/--no-xtoggle house style, is precise to the file-overwrite concern, avoids the-fcollision (run --file), and won't be confused with the existing--rebuild/cache controls.Shared helpers (
utils/cli.py)overwrite_option()—--overwrite/--no-overwrite, default no-overwrite.guard_output(path, overwrite, *, label)— fail-fast existence check. Files block when they exist; directories block only when non-empty (a fresh/empty output dir doesn't false-trigger); aNonepath (stdout) is a no-op.Wired into 10 commands
export,optimize,quantize,compile,config,eval,analyze,perf,catalog,run.unlink().{stem}_qdq.onnx), not just explicit-o.analyzeguards both--outputand--optim-config.compileguards the resolved-ofile or--output-dir(non-empty).buildintentionally excludedbuildalready has--rebuildplus incremental resume — without--rebuild, existing stage artifacts are reused, not clobbered (e.g. quantize stage skips when QDQ nodes are present). A non-empty-output-dir guard there would break legitimate incremental rebuilds and overlap confusingly with--rebuild.Tests
guard_output/overwrite_optionunit tests (file/dir/empty-dir/overwrite-bypass/None/custom-label).catalog(file),quantize(file + default-derived path + verifiesquantize_onnxis not called when blocked),compile(empty dir OK, non-empty blocked,--overwriteproceeds).tests/unit/commands/+tests/unit/utils/test_cli.pysuite green (916 + new tests).Fixes #561