Skip to content

v0.9.1: Cellpose cell 4 opens the run once with its wait; the install shows its progress (#574 items 1-2) - #575

Merged
guijacquemet merged 3 commits into
mainfrom
claude/cellpose-install-folders
Nov 26, 2026
Merged

guijacquemet merged 3 commits into
mainfrom
claude/cellpose-install-folders

Conversation

@guijacquemet

@guijacquemet guijacquemet commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

This PR covers items 1 and 2 of #574, from the owner's Colab test of MorphoBricks_Preprocessing_Cellpose on 26 Nov. Items 3 to 5 and the preview display are out of scope. No pins are moved.

Item 2: the Folders step showed nothing for minutes

  • What happened: cell 4 opened the app's run twice before its widget was displayed. The first opening was for the notice's refusal (_refusal → open_run), the second came from Open the run (segmentation_app → opener.submit()). For a verify_content run, every opening reads every image whole to compute its content SHA-256 (RunInputs._check_files → content_changed).
  • Reads per image, counted by patching file_sha256: 2 before, 1 now. The viewer's first image is read as before; that is the preview, which is out of scope.
  • run_inputs.open_checked(..., checking=): RunInputs.open now calls it and keeps its pinned signature. The checks, their order, the result and the refusals are all the same as before. It reports a (phase, done, total, path) callback for each phase in open_checks.OPEN_PHASES (the Run: show every check before the first image read, and make the header check linear (v0.9.0 release blocker) #567 signature).
  • notebook_open_progress.opening: shows the open with notebook_progress.Wait and its ticking thread. The line gives the phase, "n of N" with the current image, and the elapsed time. It ends with "Opened and checked in m:ss.", or "Stopped after m:ss." when an error or an interrupt went through.
  • Cell 4's code is unchanged and byte-identical to main, so it also runs against the pinned RELEASE_REF 3af7891:
    segmentation = segmentation_step(notebook)
    display(segmentation)
    
    In a kernel, segmentation_step now displays the widget itself before opening the run. The cell's display(segmentation) then adds nothing, because SegmentationStep._ipython_display_ skips that one call; later displays work as for any widget. Outside a kernel nothing is displayed. show= overrides the default. No re-pin is needed for this cell.
  • Errors while cell 4 opens the run: a refusal is shown in the form. Any other error leaves the cell as it did before (StepForm.submit(reraise=True)) and is also shown under Open the run. An error from pressing the button stays under the button.

Item 1: the first install is slow and shows nothing

  • Measured in a fresh Python 3.12 venv, real pip, no cache:
    • Cell 1 does not install Cellpose. Its first run took 42 s and its second 1.6 s.
    • Cell 4's Install Cellpose step downloads 3.2 GB without PyTorch. With PyTorch already installed it takes 5 to 8 s; Colab ships PyTorch, but these timings were not measured on Colab.
  • What was wrong: pip printed to the kernel's own stdout, which a button callback does not show.
  • Now:
    • install_cellpose(ticked, output=) streams pip's lines through Popen(..., errors="replace").
    • pip is killed and waited for if anything stops the reading, an interrupt included, as subprocess.run did.
    • While pip runs, the card says what pip is doing, with a ticking elapsed time.
    • When pip finishes, a green card lists every package installed or changed and how long it took.
    • A failed install shows pip's last 20 lines.
  • Unchanged: the tick, the pinned release, the restart rule, and cells 1 to 3.

Review (CHANGES NEEDED on bf2afe8), addressed in 8ddd435

  1. pip kept running after an interrupt. Fixed: try/except BaseException: kill(); wait(); raise. The test interrupts the reader and checks that a real child process was killed.
  2. TypeError on main from show= in cell 4. Fixed without a re-pin: cell 4 is back to its pinned text, and the display moved into segmentation_step (see above).
  3. The register_step( check for cell 5 had been dropped. Restored.
  4. "Opened and checked in" was written even after an exception. Fixed: the line now says "Stopped after m:ss." in that case.
  5. Undecodable pip output could break the stream. errors="replace" added, with a test using a non-UTF-8 byte.
  6. Errors that are not refusals were swallowed. Agreed and fixed. The tests use an IPython stand-in so that widgets.Output swallows errors as it does in a kernel:
    • a cell-4 open that raises OSError leaves segmentation_step;
    • an error from a button press, and a refusal, stay in the form.

Tests

  • New tests:
    • tests/test_cellpose_folders_open.py (11 tests): reads per image, display before any read, the wait's lines, open_checked against RunInputs.open, refusals, the "Stopped after" line, self-display and the skipped display, and errors raised versus kept.
    • 5 install tests in tests/test_notebook_preprocessing_cellpose.py.
  • Full tools/check.py on bf2afe8: 8822 passed, 32 skipped, 0 failed. The skips are skimage missing, release-only tests, and platform-dependent tests.
  • On 8ddd435 (focused runs only):
    • Cellpose notebook, form, app, install, republish, run-inputs and file tests: 188 passed, 3 skipped (release-only).
    • API-surface, error-class, debt, worker and progress tests plus the combined-notebook tests: 246 passed.
    • Ruff and tools/check.py --rules are clean.
    • The full suite was not rerun: the only src changes are the review items.
  • Not done: Colab and JupyterLab rendering were not checked by eye; the widgets were tested headless.

Links #574.

🤖 Generated with Claude Code

https://claude.ai/code/session_01WX6rdMV1r5jUPUR94kxV5a

…progress (#574)

Item 2, the silent Folders step: cell 4 opened the app's run twice before its
widget was shown (once for the notice's refusal, once by Open the run), and
each opening of a verify_content run reads every image whole for its content
SHA-256. Cell 4 now shows the widget first (segmentation_step(notebook,
show=display)), then opens the run once: 1 whole read per image instead of 2.
run_inputs.open_checked is RunInputs.open (which now calls it, signature kept)
telling a (phase, done, total, path) callback each phase of
open_checks.OPEN_PHASES; the checks, their order, result and refusals are the
same. notebook_open_progress.opening shows them with notebook_progress.Wait and
its ticking thread (#567): the phase, n of N with the image, the elapsed time.

Item 1, the slow, silent first install: the shared cell 1 does not install
Cellpose (measured: 42 s first run in a fresh venv, 1.6 s second run); cell 4's
own Install Cellpose step does. Its pip output went to the kernel's own output,
invisible from a button. install_cellpose now streams pip's lines; the card
shows what pip does now with a ticking time, then what it installed or changed
(a failed install shows pip's last lines). The tick, the pinned release, the
restart rule and the shared cells 1 to 3 are unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WX6rdMV1r5jUPUR94kxV5a

Copy link
Copy Markdown
Contributor Author

Full python tools/check.py result on bf2afe8 (Python 3.12, local dev venv):

  • Ruff: all checks passed. Code rules: no new violations.
  • pytest: 8822 passed, 32 skipped, 0 failed (44 min).

None of the skips are caused by this PR:

  • 11 need skimage, which this venv does not have.
  • 1 is release-only (the notebook pins: MORPHOBRICKS_RELEASE_RUN=1).
  • The rest depend on the platform: case-insensitive file system, root ignoring POSIX permissions, and similar.

The new tests ran and passed: tests/test_cellpose_folders_open.py and the three install tests.


Generated by Claude Code

- _pip kills and waits for pip when the reading stops (an interrupt
  included), as subprocess.run did; undecodable output is replaced.
- Cell 4 is back to the pinned release's call. In a kernel,
  segmentation_step displays the widget first itself and the cell's
  display(segmentation) then adds nothing, so the cell works with both
  the pinned code (3af7891) and this code.
- An error that is not a refusal while cell 4 opens the run leaves the
  cell again (StepForm.submit(reraise=True)); a button's stays under it.
- The opening's line says "Stopped after m:ss." when an exception went
  through it.
- Restore the register_step( check of cell 5 in the notebook file test.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WX6rdMV1r5jUPUR94kxV5a
SegmentationStep._ipython_display_ drew the widget with
_repr_mimebundle_, which ipywidgets 7.7 (Colab) does not have: the
first display raised AttributeError, which IPython swallows, so the
widget never appeared. It now uses the parent's _ipython_display_ when
there is one (ipywidgets 7) and _repr_mimebundle_ otherwise (8). Tests
cover both branches; the cell-4 tests also pass under ipywidgets 7.7.5.
The docstring says the skip is consumed by the next display of that
same step only.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WX6rdMV1r5jUPUR94kxV5a

Copy link
Copy Markdown
Contributor Author

Re-review blocker fixed in 85a4b06.

What was wrong: SegmentationStep._ipython_display_ drew the widget with _repr_mimebundle_. ipywidgets 7.7.5 does not have that method (checked: Widget has _ipython_display_ and no _repr_mimebundle_). On ipywidgets 7, as on Colab, the first display raised an AttributeError, so the widget never appeared.

Fix: it now calls the parent's _ipython_display_ when there is one (ipywidgets 7), and display(self._repr_mimebundle_(), raw=True) otherwise (ipywidgets 8). The docstring now says that the skip is used up by the next display of that same step only.

Tests:

  • The display test no longer depends on the ipywidgets version.
  • New: one test per branch, faking ipywidgets 7 (a parent _ipython_display_, no _repr_mimebundle_) and ipywidgets 8. The ipywidgets 8 test skips under 7.
  • In a separate venv with ipywidgets 7.7.5, the cell-4 tests pass: test_cellpose_folders_open, test_notebook_preprocessing_cellpose, test_notebook_preprocessing_cellpose_file, test_notebook_cellpose_form and test_notebook_cellpose_app. That was 71 passed and 2 failed before the test fix (both failures were in my tests, not the code), then test_cellpose_folders_open alone gave 12 passed and 1 skipped. Under 8.1.9 it gives 13 passed.
  • With real IPython (InteractiveShell) I ran cell 4's two lines followed by one more display(segmentation). On both 7.7.5 and 8.1.9, two widget views are published, each with application/vnd.jupyter.widget-view+json: the step's own display, then the later one. The cell's own display is skipped as intended.
  • Focused tests on 8.1.9 (Cellpose notebook, form, app, install, republish and file tests, API surface, debt): 196 passed, 3 skipped (release-only). Ruff and tools/check.py --rules are clean.
  • The full suite was not rerun. The last full run was on bf2afe8: 8822 passed, 32 skipped.
  • I still have not looked at it in Colab itself.

Generated by Claude Code

guijacquemet pushed a commit that referenced this pull request Nov 26, 2026
open_run now opens through run_inputs.open_checked (the hunks shared with
#575), so the test that publishes the run while it is opened patches that
function instead of RunInputs.open. Same change, byte for byte, as #575's.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WX6rdMV1r5jUPUR94kxV5a
@guijacquemet
guijacquemet marked this pull request as ready for review November 26, 2026 15:32
@guijacquemet
guijacquemet merged commit 5c05644 into main Nov 26, 2026
3 checks passed
@guijacquemet
guijacquemet deleted the claude/cellpose-install-folders branch November 26, 2026 15:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants