Repository navigation
Conversation
- Every import subcommand checks its target, and its input's shape where the path sets one, before the source is copied: dataframe, dict and image refused a forbidden target, a CSV of the wrong length or an image of the wrong height only after a copy of the whole store. The copy is reported once the import has succeeded (F181). - Image inputs are decoded only as the formats the docs name: PNG, JPEG and TIFF for import image, PNG for Visium's tissue images (F182). - Control characters in names print as visible escapes, in every message and in ls --plain, which now writes one path a line (F183, F186). - A reader that stops early (| head) ends any command quietly, with exit code 0, ls and view included (F184). - Python warnings print as one Warning: line through the console (F185). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
import dataframe's pre-check read the CSV once more to count its rows, on top of the import's own two passes. import_dataframe is split into scan_dataframe (the target and the first pass, with every refusal the file alone can show) and write_dataframe (the length against the store, then the second pass), with no change in behaviour or messages. The pre-check makes the first pass and the write reuses it, so a CSV is read twice in all, and its header refusals also come before the copy. formats/dataframe.py joins B3's files for this. A closed pipe on a command's results now always ends it with exit 0: every message goes through Rich's console, which itself ends a run with exit 1 when stderr's reader has gone, so the stderr probe in _reader_stopped only turned `ls -1 2>&1 | head` into exit 1. A test shows that a store writer with no reader for its messages stops with exit 1 and writes nothing. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- A run started with stdout closed (`>&-`) has no sys.stdout; flushing it before the run ended raised AttributeError after the work was done. _flush_stdout and _silence now allow for it. - The results console no longer makes itself quiet for the rest of the process on a closed pipe: it drops what could not go out and passes the error on, so a caller embedding main() can run again. - --version, printed outside any command, ends quietly too. - view through a real pipe replaces a test that raised the error itself and would have passed without the console's fix. - The docs say which reader's stopping ends a command with exit 0, and that a store writer whose messages lose their reader stops with exit 1. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- import_json is split into plan_json (the target, the file read and planned whole, every refusal the file alone can show) and write_json, with no change in behaviour or messages. The pre-check plans the JSON before the store is copied, and the write reuses the plan: a JSON array for uns, a file of null, a key no element can be named and a file cut short were refused only after the copy. - Visium's _images() opens each tissue image's header as PNG while planning (conversion/spatial.open_tissue_image, through formats.image.open_image), so a non-PNG is refused before the output is staged, not part way through writing it. - AGENTS.md and docs/developers.md: B3's rules (a closed pipe in _fail, Python warnings as Warning: lines, visible for text written without Rich, untrusted images through open_image). formats/json_data.py, conversion/visium.py (_images only), AGENTS.md and docs/developers.md join B3's files for this. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- The CSV's first pass now comes a whole copy before its second, so a value the scan never saw (a new category) would be written as a gap, with exit 0. The scan records the file's size, modification time and inode, and the write refuses the file if they changed, before and after its pass. - A message whose reader has gone (`2>&1 | head`) is dropped and the command finishes, so its exit code says whether it wrote its output. Rich ended the run at the first such message, with exit 1, whether that came before the store was written or after it was in place, and made the console quiet for the rest of the process. - The docs say so, and that the import's target is checked against the layout before the copy. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
`adata export dataframe in.h5ad obs -o obs.csv >&-` ended with `'NoneType' object has no attribute 'flush'` and exit 1, and staging threw the finished file away; `export dict` and `export array` did the same. Started with stdout closed, Python has no sys.stdout, and stdout_reader_may_stop flushed it even for a file. It now skips the flush when there is none, and _silence_stdout allows for it. Found by review; already broken on main. formats/common.py joins B3's files. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
831bd24 rewrote test_a_run_with_stdout_closed_still_succeeds and, with it, deleted _messages_unread, which the next test uses: that test failed with NameError on the pushed commit. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Test Results (py3.13)3 986 tests 3 973 ✅ 10m 34s ⏱️ Results for commit f8264d5. |
Test Results (py3.12)3 986 tests 3 973 ✅ 12m 22s ⏱️ Results for commit f8264d5. |
Part of #149 (wave 1, for 0.17.11). Closes #137.
Fixes F181, F182, F183, F184, F185 and F186. Each has a regression test whose docstring starts with its ref and says what used to go wrong. Every one of those tests fails on
main, except a control showing that PNG, JPEG and TIFF still import, and two guards on the design: the CSV is still read in two passes, and a store writer whose messages lose their reader still exits 1.What changes
import dataframe,import dictandimport imagenow go through the same pre-check asarrayandsparse. It runs after the output check and before staging copies the source.import_dataframeis split intoscan_dataframeandwrite_dataframe, with no change in behaviour or messages. The pre-check makes the CSV's first pass and the write reuses it, so the CSV is still read in two passes. Its header refusals come before the copy too.import_jsonis split intoplan_jsonandwrite_jsonthe same way. The pre-check reads and plans the file, and the write reuses the plan.Copied in.h5ad → out.h5adis printed once the import has succeeded._source_rootstill runs 0.17.9'scheck_zarr_contents.Image.open(path, formats=[...]), limited to the formats the docs name: PNG, JPEG and TIFF forimport image(formats/image.open_image), and PNG for Visium's tissue images. Any other file is refused with its name.--no-images.literal()shows C0, DEL and C1 control characters as visible escapes (\x1b,\n, as Python spells them), so every message, tree and status line is covered.ls --plainwrites its paths through the same escaping (visible()), so a name holding a newline stays on one line.BrokenPipeErrorreaching_failends the run quietly with exit 0, with stdout pointed at /dev/null, asexportalready did. That coversls,view,export image,--versionand any later command.on_broken_pipe) and staying quiet for the rest of the process.2>&1 | head) is dropped, and the command finishes, so its exit code says whether it wrote its output. Rich used to end the run at the first such message with exit 1, whether that came before the store was written or after it was in place. It also made the console quiet for the rest of the process. A test covers both outcomes.mainflushes stdout before the run ends, so short output still waiting in the buffer cannot make Python exit with 120.>&-) is fine. That includesexport ... -o file, which already failed onmain: the review found thatformats/common.stdout_reader_may_stopflushed a stdout that did not exist, and staging threw the finished file away.mainshows Python warnings as oneWarning:line through the console, escaped like any other message, and putswarnings.showwarningback afterwards.Files beyond the issue's Owns line
Agreed with the coordinating session, which is adding them to #137:
formats/dataframe.pyandformats/json_data.py: no batch owns either. Refusing what a CSV or JSON file holds before the copy needs the file read first. Without the split, the import would have read it once more after the copy.formats/table.py(B10's) andformats/validate.py(B6's) are called as they are.conversion/visium.py, in_images()only: so that a non-PNG tissue image is refused while planning, as AGENTS.md's "validate before the output exists" asks, rather than during the write.formats/common.py: two lines. The export helper flushed a stdout that a run started with>&-does not have. No batch owns the file.AGENTS.mdanddocs/developers.md: only the lines on B3's rules. These are_failon a closed pipe,Warning:lines,visible, and untrusted images throughopen_image. They are in the architecture and rules sections, outside the Releases sections B5 is editing.User docs:
commands.md(the intro,ls -1,import,import image), the pipelines guide's exit codes section, the Visium page, troubleshooting (two new refusals, and the warnings section), and the testing map row.Changelog entry (for 0.17.11,
### Fixed)importrefuses before it copies the store(#137).
import dataframe,import dictandimport imagerefused a target the layoutforbids, a CSV of the wrong length, a JSON file that cannot be written
there or an image of the wrong height only after copying the whole store,
which takes as long, and as much room, as the store is large. Now every
subcommand checks its target and its input first, as
arrayandsparsealready did; a CSV's first pass and a JSON file's parse simply come before
the copy, so neither is read more than before.
Copied in.h5ad → out.h5adis printed only once the import has succeeded.
(#137). Pillow picked
a decoder for an image from among all of its plugins, whatever the file's
name.
import imagenow reads PNG, JPEG and TIFF, and Visium's tissueimages are read as PNG; a file of any other format is refused, before
anything is written.
(#137). A store's
member names, labels and attribute values reached the terminal as they
were. A control character in one now prints as an escape such as
\x1bor
\n, in every message and inls.ls -1writes such a name on oneline, where a newline used to make it two paths.
(#137).
adata ls data.h5ad -1 | head -1andadata export image ... | headprintedError: Broken pipeand exited 1, which fails apipefailscript.lswithout
-1,viewand--versionexited 1 as well, without a word.Only the other exports ended quietly (B2b: Table, dataframe, JSON and array codecs #91). Every command now ends
quietly, with exit code 0.
Warning:lines(#137). A warning
from the storage layer or a library printed in Python's own format, with
the tool's source file, line number and line of code. Each is now one
Warning:line on stderr, like the CLI's own.Repros
Each of the audit's repro scripts for these refs prints
OK:on this branch; each printedDEFECT:onmain.Review
An independent review of the first commit found:
--versionon a closed pipe;All are fixed. A second review of the commits after it found:
The first two are fixed. So is the review's finding that exports to a file failed when started with stdout closed, which was already broken on
main.Tests
uv run pytest -m "not integration": 4184 passed, 9 skipped (on macOS, Python 3.12)uv run pytest -m perf: 210 passedLeft as they are
A target inside an existing dataset (
import dict in.h5ad uns/k/subwhereuns/kis an array) still fails after the copy, with the library's own message. So does a.npythe import cannot read at all (Python objects, a file cut short), whose header the pre-check leaves to the import. Both are as onmain.formats/array.pyis B6's.--helpon a closed pipe still exits 1. It goes through typer's own Rich console, and Rich ends the process itself. In practice the help fits in the pipe's buffer, so--help | headexits 0.ls -1escapes control characters but leaves a backslash as it is. A name holding a real newline and one holding a backslash andntherefore print alike. Escaping backslashes would change every listed path that holds one. A raw-0mode would put a hostile name's escape sequences on the terminal of anyone who runs it without a pipe.formats/common.stdout_reader_may_stop, which each export still uses, now does what_faildoes. It is not B3's file; it could go in a later cleanup.🤖 Generated with Claude Code