Repository navigation
Conversation
- tract_math: an existing output file triggered an `input()` prompt, so non-interactive runs failed with `EOFError`. Add a `--force` flag that overwrites without asking, and fail with a message naming `--force` when stdin is not a terminal. - tract_querier: an output prefix such as `out/subj.01` took `.01` as the output format and only failed after all the queries ran. Check the format against .trk, .vtk and .vtp right after parsing the options. - tract_math: close the CSV output (opened with `newline=''`) and the tractography files that `argparse.FileType` opens to check they exist. - shell: remove the debug `print(line)` echoing every input line. - `TractQuerierSyntaxError` and `TractQuerierLabelNotFound` render their message with `str()` instead of `repr()`, so multi-line messages print as such. - Fix the help texts of `tract_remove_short_tracts`, `tract_affine_transform` (missing `ref_image`) and `tract_point_distance_min_max` (it prints the shortest and longest tract lengths). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Nov 4, 2026
This branch has not been deployed
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 was wrong
Items of #118 addressed here:
process_outputasksOverwrite file ... (y/N)?withinput(); in a batch run (stdin not a terminal) this fails withEOFError. Reproduced:tract_math tract.trk count existing.csv < /dev/nullends inEOFError: EOF when reading a line.-o out/subj.01takes.01as the output format; reproduced: the files are loaded and the queries computed, then the first save fails withOSError: File format not supported.newline=''and never closed; the tractography files opened byargparse.FileType('r')are never closed.TractQuerierCmd.defaultechoes every input line (print(line)).TractQuerierSyntaxError.__str__andTractQuerierLabelNotFound.__str__returnrepr(self.value), sostr(e)is quoted and a multi-line message shows a literal\n.tract_remove_short_tractssays it "subsamples";tract_affine_transformomitsref_image;tract_point_distance_min_maxclaims to report distances between consecutive points but prints the shortest and longest tract lengths (tract_lengthreturns the total length of each tract).The change
tract_math: new--forceoptional flag (handled in the decorator, alongside the existing--flags) overwrites an existing output without asking. Without--force, if stdin is not a terminal, the command fails withOutput file <name> exists, use --force to overwrite itinstead of prompting. With a terminal, the prompt is unchanged.--forceis documented in the usage text.tract_querier: the output format is worked out right after the options are parsed (the same logic, moved up; the earlier dead assignment oftractography_extensionis removed) and must be.trk,.vtkor.vtp(the formatstractography_to_filewrites). Otherwise:error: output format '.01' not supported, it must be .trk, .vtk or .vtp; add it to the output prefix, e.g. -o out/subj.01.trk.with, opened withnewline=''; theFileTypehandles are closed right after parsing (.nameis all that is used afterwards).print(line)removed fromshell.default.__str__returnstr(self.value). Callers inshell.pyandcli_tract_querier.pyprinte.value, so their output does not change; no test matched on the quoted form.tract_remove_short_tracts"keeps only the tracts longer than the given length";tract_affine_transformlists<ref_image>and says it gives the output's affine and dimensions;tract_point_distance_min_max"minimum and maximum tract length".Behaviour changes: a non-interactive
tract_mathrun with an existing output now exits with an error (exit code 2) instead of anEOFErrortraceback;tract_querierwith an unsupported output extension now errors before loading any file;str()of the two exceptions no longer has quotes.Not addressed here
cli_tract_querier.pystill usesoptparsewithversion=0.1(handled separately).tract_math's parser readssys.argvwhile it is built.tract_querierhas no overwrite prompt (it overwrites silently), so no--forcewas added to it.cli_tract_math.py,TractMathWrongArgumentsErroris caught withtraceback.print_exc()beforeparser.error, so the new--forcemessage is preceded by a traceback on stdout.tract_affine_transform's[invert]is effectively required (the decorator rejects three positional arguments) andbool(invert)is true for any non-empty string, includingFalse;tract_point_distance_min_max's name suggests it was meant to report point-to-point distances. The help now describes what the code does; the code is unchanged.Testing
pytest -q -p no:cacheprovider tract_querier: 45 passed, 1 skipped (master: 42 passed, 1 skipped).test_tract_math.py::test_tract_math_existing_output: with an existing output and a non-terminal stdin,tract_math ... count out.csvfails, mentions--forceand leaves the file untouched; with--forceit overwrites it and the CSV reads back as 2 rows with 6783 tracts.test_tract_querier.py::test_tract_querier_unsupported_output_format:-o <tmp>/subj.01fails with the format error and beforeLoading files.test_tract_querier.py::test_syntax_error_message_is_not_quoted.tract_math tract.trk count existing.csv < /dev/nullgives the--forcemessage and keeps the file. I did not test the interactive prompt in a terminal (that code path is unchanged).Merge order
Touches
scripts/cli_tract_querier.pyin different hunks from #126 (#99);git merge-treeshows no conflict between the two. Small edits (help strings, a usage line, a few lines inmain) intract_querier/tract_math/operations.py,scripts/cli_tract_math.py,tract_querier/shell.pyandtract_querier/query_processor.py, which other open PRs on #102, #105, #106, #112, #38, #103, #104 and #115 may also edit: a rebase may be needed depending on which lands first.Part of #118
🤖 Generated with Claude Code