diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 08f3ffdc..9c0e1025 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -127,13 +127,29 @@ jobs: if: env.MORPHOBRICKS_RELEASE_RUN == '1' shell: python run: | + import json + import pathlib import xml.etree.ElementTree as ET + # The test is parametrized by notebook (name[notebook]): every notebook with a + # RELEASE_REF must have its own case, run and passed. RELEASE_ONLY = {"test_release_only_the_preprocessing_pin_is_a_commit_with_this_code"} - cases = {c.get("name"): c for c in ET.parse("tests.xml").getroot().iter("testcase")} - for name in sorted(RELEASE_ONLY): - case = cases.get(name) - assert case is not None, f"{name} did not run" - assert len(case) == 0 or all(c.tag in ("system-out", "system-err") for c in case), ( - f"{name} did not pass: {[c.tag for c in case]}" + pinned = sorted( + path.stem + for path in pathlib.Path("notebooks").glob("*.ipynb") + if any( + "RELEASE_REF" in "".join(cell.get("source", "")) + for cell in json.loads(path.read_text(encoding="utf-8"))["cells"] + if cell.get("cell_type") == "code" ) - print(f"{name}: passed") + ) + assert pinned, "no notebook has a RELEASE_REF" + cases = {c.get("name"): c for c in ET.parse("tests.xml").getroot().iter("testcase")} + for base in sorted(RELEASE_ONLY): + for notebook in pinned: + name = f"{base}[{notebook}]" + case = cases.get(name) + assert case is not None, f"{name} did not run" + assert len(case) == 0 or all( + c.tag in ("system-out", "system-err") for c in case + ), f"{name} did not pass: {[c.tag for c in case]}" + print(f"{name}: passed") diff --git a/AGENTS.md b/AGENTS.md index b7eeeda7..88337846 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -1330,9 +1330,15 @@ jupyter lab notebooks/MorphoBricks_Preprocessing.ipynb --- -## 11. Status (current state, v0.8.0) - -- **Released:** v0.8.0 (19 November 2026), a minor release because of its breaking entries +## 11. Status (current state, v0.9.0) + +- **Released:** v0.9.0 (24 November 2026), a minor release, Stable 1: two notebooks + (`MorphoBricks_Preprocessing` and `MorphoBricks_Preprocessing_Cellpose`, #441; + `MorphoBricks_Cellpose` stays until the owner's Colab test), normalization pinned at v0.8.0 + (#471), the Spec pin at `232fb38` (fast mode, ADR 0006; draft file version 4), run integrity + checked at read and open (#480, #489, #490, #491) and the conversion and publication fixes + (#400, #447, #448, #467, #482, #488, #497); run manifest version 5 unchanged. + v0.8.0 (19 November 2026), a minor release because of its breaking entries (`imagecodecs` required, codecs without a measured bound refused; no format change): lazy windows (#339, `docs/design/lazy-windows.md`) with `window_map` / `map_windows` (#346), the array H&E tissue mask `he_tissue_mask_array` (#343), the `max_ram` worker planner (#341), window memory diff --git a/CHANGELOG.md b/CHANGELOG.md index 072997e2..704c9f24 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,8 +6,30 @@ The design is `docs/restart/preprocessing-design-v0.4.md` in MorphoFeature, on b are in [docs/plan.md](docs/plan.md) §12. (The v0.3 to v0.4 migration guide was removed in v0.5.1: no run before v0.5.1 is read.) -## Unreleased - +## v0.9.0 (24 November 2026) + +**Stable 1: two notebooks, normalization v0.8.0, and the integrity fixes.** A minor release +(semantic versioning before 1.0, `docs/development.md`): the user-facing notebooks are now two, +`MorphoBricks_Preprocessing.ipynb` (images to a run ready for MorphoFeature) and +`MorphoBricks_Preprocessing_Cellpose.ipynb` (the same three cells, then Cellpose segmentation and +mask registration, #441); `MorphoBricks_Cellpose.ipynb` stays until the combined notebook has +passed the owner's Colab test. Normalization is pinned at v0.8.0 (#471, additive). The Spec pin +moves from `bf68d30` to `232fb38` (fast mode, Spec ADR 0006), so drafts written under the old pin +are refused (`spec_commit_mismatch`) and the draft file is version 4. The run manifest stays +version 5; a run's integrity is now checked when it is read and opened (the description's +section digests, unit records and channel coverage, #489, #490, #491), mask headers must be bound +to a fingerprint (#480), and conversion and publication no longer write through links, remove +files they did not write or leave a new description with an old design (#400, #447, #448, #467, +#482, #488, #497). Tagging channels by repeat can override a listed unit with a per-unit +review (#376): a unit whose headers disagree with its row counts only once that unit is +confirmed, fast mode never tags it, and the refusals and confirmations are kept in the draft +(`tag_review`). A whole biological repeat or condition can be removed, its IDs staying listed in +`used_ids` (#283). NumPy 2.0 or later is required. CI runs minimal gates on pull requests and the +full matrix at release; the notebooks' `RELEASE_REF` moves only in the release PR. + +- **Follow-ups of #535 and #534 (#543, refs #542).** A spelling of a listed ID that is removed in the same save (remove `rep2`, add `REP2`) is no longer proposed, and `confirm_id` refuses it on the candidate with `E_ID_CASE_COLLISION`; the listed spelling itself stays allowed, so a folder that keeps its ID is unaffected. `draft_from_discovery` now documents that a caller who publishes after a removal must pass `listed_ids=description.used_ids` (otherwise `R_USED_ID_DROPPED`, which fails safe). `read_manifest` refuses a duplicated or unsorted `projection.images` (every tag from v0.5.0 to v0.8.0 sorts the entries by `relative_path`, so valid manifests read as before). The user guide names the removed folders in the per-condition question. `tests/test_draft_answers.py`, `tests/test_notebook_whole_removal.py`, `tests/test_run_projection.py`. +- **Kernel benchmarks and a strict-description-reader benchmark (#544, refs #106 and #505).** Measuring only; no file under `src/` changes. `tools/benchmark_harness.py`, `tools/benchmark_inputs.py`, `tools/benchmark_kernels.py` (histogram, reads, masks, channel identity), `tools/benchmark_reads.py` and `tools/benchmark_description_read.py` record time, traced memory and a SHA-256 of every output on seeded inputs; the baselines and their machine are in `docs/benchmarks.md` and `docs/benchmark_results/2026-11-25-*.json` (not performance claims). The reader benchmark found `description_semantics._repeat_membership` quadratic in the repeats, which #545 fixes. `tests/test_benchmark_kernels.py` runs both tools in `--quick` mode. +- **Cellpose Preview shows only its own result (owner's Colab test of v0.9.0, 26 November 2026).** Some nuclei results of the first Preview stayed on screen after later ones. The result (the card and the figures) was displayed into the step's output area, and its clearing was left to the frontend; a Preview that failed (Cellpose, or the model's load) also kept the earlier result in `previewed` and the Segment step's line still compared with it. The result is now held by one box of widgets (`CellposeWorkflow.preview_box`, the figures as PNG pictures), emptied when Preview is pressed (before the model is loaded); when the output or a mask type changes; when a channel dropdown, a channel number or By tag/number changes (Preview and Segment re-read them; Segment's line then says "not previewed yet"); when a field of the model step changes (model, device, diameter, thresholds, batch size, the nuclei's own model; Segment's line still names what changed since the last Preview); when a model is loaded; and when a Preview fails. The example image dropdown does not clear it: the result names its image. While Cellpose runs, the box says "Running on the preview image…". Nothing is written or recorded by a Preview, as before. `tests/test_notebook_cellpose_preview_stale.py`. - **The run shows its own folder and header check, and that check is no longer quadratic (owner Colab test of v0.9.0, 25 November 2026).** On a large mixed-layout experiment, *Run* showed "Preparing: checking the folders and the image headers again · 0:00 elapsed" for 10-15 minutes before the first image: the run checks every header again (bound to its fingerprint) with no progress reported, and the elapsed time was redrawn only on a progress report. The run now reports that check through `RunMode(checking=...)` (preflight's `(phase, done, total, path)`, operational only like `workers`; `run_experiment`'s parameters are unchanged), and the notebook shows each phase and each header of how many ("Preparing: reading the image headers again · 120 of 24,000"), with the elapsed time redrawn every second by `Wait.ticking()` while the run works. While it goes, the notebook says that a cell run meanwhile waits for it, and how to interrupt it. Two steps of the check were O(n²): each image's staging key took `MetadataReport.dtype` (a pass over every header) and the mask-name screen compared each image's name with every other one (`mask_names._mask_owner` now looks up the prefixes of the name). The outputs are byte for byte the same (`plane_histograms.csv`, `experiment_design.csv`, `image_qc.csv` of a 4,800-image three- and two-channel tree); the check before the first image took 30.0 s → 10.3 s for 12,000 images and 72-75 s → 24-27 s for 24,000 on local disk (`tests/test_run_checking_progress.py`). In a `verify_content` run (the notebook's default, and any run on a fresh output folder) the run then reads every image whole for its content SHA-256 before the first pixel is read: on Google Drive that pass, not the header check, is what took minutes (owner: about 200 images, 10-15 minutes). It is now reported too, as the phase `contents` (`run.phases.CONTENTS`, "Preparing: reading each image whole for its content SHA-256 · 12 of 200"); what is read and verified is unchanged. - **Earlier work that does not record its experiment folder no longer leaves the stepper at a dead end (owner's Colab test of v0.9.0 at ca3b3c6).** An output folder holding only saved answers (here an older version's `morphobricks.draft.json`) showed *"The experiment folder it is of is not recorded … Enter the experiment folder and click Check folder"*: the stepper has no *Check folder* button (its check, *Looks right: read all image headers*, stays disabled until **Scan the folders**), and entering the folder showed the same message again, with no scan and no picture. Now the experiment folder entered is scanned at once on the stepper (folder walk and one picture; nothing is written), the message names the stepper's own buttons, and the check, on the user's click, reads the saved answers as always. Saved answers written by another version of the software (`DraftFileError` `unknown_version`, `unknown_key` or `spec_commit_mismatch`; the owner's file is format 3, `unknown_version`) are not earlier work (`EarlierWork.old_answers`): one line says they are not used and the file is left as it is, and the experiment folder entered is scanned and shown as above (an early **Scan the folders** click, before the typed folder reached the kernel, is made good when it arrives). The same scan follows a record and a run that name different folders. Each message names the buttons of the layout shown (the stacked pages say **Check folder**). Tests: `tests/test_notebook_restore.py`. - **A saved repeat order is never replaced by an abandoned *Yes* (review of #546 at e40f1ad).** On a reopened per-repeat draft, picking *Yes*, filling its row with rep1's order and going back to *No, per repeat folder* showed rep1's order in every repeat row, under "Pre-answered from your saved tags", and one Submit published it for every unit. A row's own saved tags now rank above a broader choice of the session (`channel_scope.seed`: the row's choice, its saved tags, a broader choice, the header names), and the "Pre-answered" note goes at the first change of the answer or of a row. Tests: `tests/test_notebook_channel_guide_reopen.py`, `tests/test_channel_scope.py`. diff --git a/README.md b/README.md index 7db481ea..811e5caa 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ from there. ## Status -Pre-alpha; the current release is v0.8.0 (what is planned next is in +Pre-alpha; the current release is v0.9.0 (what is planned next is in [docs/roadmap.md](docs/roadmap.md)). Implemented and tested: - Folder discovery and validation, TIFF and OME-Zarr header inspection without reading pixels @@ -74,7 +74,7 @@ contract version 3 and an objects use with `RunInputs.read_objects`. See the ## Installation ```bash -pip install "git+https://github.com/CellMigrationLab/morphobricks-preprocessing.git@v0.8.0" +pip install "git+https://github.com/CellMigrationLab/morphobricks-preprocessing.git@v0.9.0" ``` For development, from a clone: @@ -84,7 +84,7 @@ pip install -e ".[dev]" ``` The optional `notebook` extra installs the widget dependencies for the notebook -(`pip install "morphobricks-preprocessing[notebook] @ git+https://github.com/CellMigrationLab/morphobricks-preprocessing.git@v0.8.0"`). +(`pip install "morphobricks-preprocessing[notebook] @ git+https://github.com/CellMigrationLab/morphobricks-preprocessing.git@v0.9.0"`). The notebook's first code cell (**1. Install**) can set this up automatically: it uses a nearby checkout or an installed package only when it is the pinned `RELEASE_REF` commit (never by version alone), and installs missing requirements into the active kernel. A standalone @@ -251,7 +251,7 @@ ruff format . pytest ``` -Coding conventions are described in [docs/development.md](docs/development.md). Planned work after v0.8.0 is in [docs/roadmap.md](docs/roadmap.md). +Coding conventions are described in [docs/development.md](docs/development.md). Planned work after v0.9.0 is in [docs/roadmap.md](docs/roadmap.md). ## License diff --git a/docs/colab-release-check.md b/docs/colab-release-check.md index 07b77d1f..0867fff7 100644 --- a/docs/colab-release-check.md +++ b/docs/colab-release-check.md @@ -19,7 +19,7 @@ Write the date, the commit and any failure (as an issue number) next to each ite - **Time-lapse:** a small experiment of time-lapse images (optional; the tests cover it). **Before opening it.** `RELEASE_REF` in cell 1 is the release preparation commit, and cell 3's -`PreprocessingNotebook(...)` call is that commit's API (v0.8.0: `PreprocessingNotebook()`). The +`PreprocessingNotebook(...)` call is that commit's API (v0.9.0: `PreprocessingNotebook()`). The release PR moves `RELEASE_REF` and records the pair in `RELEASE_CALLS` of `tests/test_notebook_file.py`, which fails for a `RELEASE_REF` without one. @@ -43,7 +43,7 @@ again on the tagged commit. - [ ] One line: "… run cell 1 (Install MorphoBricks preprocessing) first …", no traceback; nothing is installed. 3. Run **cell 1**. - - [ ] It prints **Ready** with the preprocessing (0.8.0), normalization (0.8.0) and + - [ ] It prints **Ready** with the preprocessing (0.9.0), normalization (0.8.0) and ipywidgets versions and the pinned source, then names cells 2 and 3. No restart or ipywidgets upgrade is asked for; Drive is not mounted. - [ ] Run it again: nothing is installed again, the same versions. diff --git a/docs/conformance.md b/docs/conformance.md index 78aec3f7..60c3f78d 100644 --- a/docs/conformance.md +++ b/docs/conformance.md @@ -6,6 +6,48 @@ real run; a skip is never counted as a pass. Owner rulings of 8 November 2026 (i "no skips" applies to the Spec conformance modules (`tests/test_spec_*.py`); a skip elsewhere in the suite is listed as **not run**, with its reason. +## Release record: v0.9.0 (24 November 2026) + +A G1-style record of the v0.9.0 release candidate, a minor release, Stable 1: two notebooks +(`MorphoBricks_Preprocessing` and `MorphoBricks_Preprocessing_Cellpose`, #441), normalization +pinned at v0.8.0 (#471), the Spec pin at `232fb38` (fast mode, Spec ADR 0006; draft file +version 4), run integrity checked at read and open (#480, #489, #490, #491), the conversion and +publication fixes (#400, #447, #448, #467, #482, #488, #497), the channel-tag override with its +per-unit review (#376), the removal of a whole repeat or condition (#283, #535), and the work +merged since: quick fixes A and B (#534, #530), the check-folder and calibration-target fixes +(#528), the follow-ups of #535 and #534 (#543), the linear strict description reader (#545), the +kernel and reader benchmarks (#544), the guided channel step and image-type form (#546), the +restore of an output folder's earlier work (#547), the four-step Cellpose widget (#548), and the two blockers of the owner's Colab test, the restore and old-answers scan (#566) and Run progress during the pre-run checks with two linear speed-ups (#567), and the owner's Cellpose test blocker, Preview showing only its own result (#576). The +run manifest stays version 5. It does not decide a gate; deciding a gate is the owner's. + +| | | +|---|---| +| Release candidate | Measured on the tree of the merge commit `8125f8383b02a7b4ab826608a45f28d74b4f3e91` (branch `claude/release-v0.9.0` at `3a1b073`, merged with the head `1d43cd3` of #576, branch `claude/cellpose-preview-stale` on `main` at `316be56`; `main` itself is not merged, so #568, #572 and later work stay out of v0.9.0; the release branch holds #528, #534, #543, #545, #544, #530, #548, #547, #546, #566 and #567; one conflict, in the CHANGELOG, both sides kept; `git diff 3a1b073 A -- src` is exactly #576's source change, four `notebook_cellpose*.py` files; the notebooks' `RELEASE_REF`, the `RELEASE_CALLS` entry and the pin assertion are back at their pre-pin values) before this record was added; the record changes only this file, and the commit that adds it is the v0.9.0 preparation commit A (`git diff 8125f8383b02a7b4ab826608a45f28d74b4f3e91 A -- src pyproject.toml` is empty). A keeps the notebooks' `RELEASE_REF` at their v0.8.0-era pins. Commit B then points the `RELEASE_REF` of all three notebooks at A and records the pair in `RELEASE_CALLS`. | +| Spec pin | `tests/spec_fixtures/PIN.toml`: MorphoBricks-Spec `232fb38880cc487510532d99dc71d46a27005f23` (moved from `bf68d30` in this release, ADR 0006) | +| Environment | Linux, Python 3.13.18, `pip install --no-cache-dir -e '.[dev,notebook,zarr,he-mask]'` in a fresh venv (CI's extras; normalization 0.8.0, imagecodecs 2026.11.11, numpy 2.5.5, scipy 1.18.1, tifffile 2026.11.16, zarr 3.4.2, scikit-image 0.26.0, ipywidgets 8.1.9, pytest 9.2.0, ruff 0.17.6); `PYTEST_ADDOPTS` unset; run as root on a case-sensitive file system | +| Commands | `python tools/check.py` (the whole suite in one run); `python -m pytest -q -p no:cacheprovider -rs tests/test_spec_*.py`; `python -m pytest -q -p no:cacheprovider -rs tests/test_notebook_setup.py tests/test_notebook_file.py` | +| `tools/check.py` | Ruff clean, Ruff format 762 files already formatted, pytest **8843 passed, 12 skipped** (not run, below), 0 failed, code rules passed (exit status 0) | +| Spec modules (`tests/test_spec_*.py`, 30 files) | **2122 passed, 0 skipped, 0 failed** | +| Notebook pin and version tests | `test_notebook_setup.py` and `test_notebook_file.py`: **49 passed**, 0 skipped (run on the tree of the merge commit) | + +**Not run (12 skips, none in the Spec modules):** `tests/test_he_tissue_consumer_gate.py:25` +(gate P3 needs fiberfeatures v0.7.0, not installed); the editable-install identity tests +`tests/test_code_identity.py:169`, `tests/test_he_tissue_array.py:286` and +`tests/test_he_tissue_mask.py:500` (preprocessing is an editable install here, never verified; +CI's `wheel-identity` job runs them on a wheel install); three tests that need a +case-insensitive file system, `tests/test_cli_log.py:166` and `tests/test_folder_rules.py:199` +and `:230`; two that cannot run as root, `tests/test_discovery.py:665` and +`tests/test_links_store_unreadable.py:48`; and the 3 release-only freshness tests +(`tests/release_run.py:40`, +`test_release_only_the_preprocessing_pin_is_a_commit_with_this_code` for each pinned notebook), +which run in the release PR with `MORPHOBRICKS_RELEASE_RUN=1` once commit B has moved the pins. +The scikit-image tests ran (the `he-mask` extra is installed). The behaviours of the skips are +**not verified by this run**. + +**Still the owner's:** the `release` label (the full matrix as a release run), the Colab and +JupyterLab browser check (`docs/colab-release-check.md`) at commit B, and the Cellpose stepper +human test (`docs/testing/cellpose-stepper-human-test.md`), before tagging. + ## Release record: v0.8.0 (19 November 2026) A G1-style record of the v0.8.0 release candidate (first prepared as v0.7.1; renumbered by owner decision because of the breaking entries), a minor release: lazy windows diff --git a/notebooks/MorphoBricks_Cellpose.ipynb b/notebooks/MorphoBricks_Cellpose.ipynb index 50f1a715..cba78027 100644 --- a/notebooks/MorphoBricks_Cellpose.ipynb +++ b/notebooks/MorphoBricks_Cellpose.ipynb @@ -93,7 +93,7 @@ "# Both are pinned: Cellpose to the release this notebook is made for, preprocessing to the\n", "# immutable source revision that holds this notebook's code.\n", "CELLPOSE_VERSION = \"4.2.1.1\"\n", - "RELEASE_REF = \"2405083dca90fd4c0e96faca42a9c490f182a706\"\n", + "RELEASE_REF = \"338629cff2116952224ec60a98ac78b672f88ff6\"\n", "REPOSITORY = \"https://github.com/CellMigrationLab/morphobricks-preprocessing.git\"\n", "EXTRAS = \"notebook,zarr\" if \"google.colab\" in sys.modules else \"notebook\"\n", "\n", diff --git a/notebooks/MorphoBricks_Preprocessing.ipynb b/notebooks/MorphoBricks_Preprocessing.ipynb index b196ecbb..7acfcc6d 100644 --- a/notebooks/MorphoBricks_Preprocessing.ipynb +++ b/notebooks/MorphoBricks_Preprocessing.ipynb @@ -83,12 +83,12 @@ "from urllib.request import url2pathname\n", "\n", "# LabConstrictor version identifiers.\n", - "current_version = \"0.8.0\"\n", + "current_version = \"0.9.0\"\n", "notebook_name = \"MorphoBricks_Preprocessing\"\n", "\n", "# A downloaded/Colab notebook installs this immutable source revision.\n", - "RELEASE_TAG = \"v0.8.0\"\n", - "RELEASE_REF = \"438a2d37625ae7941953fa831914aa5ef5572696\"\n", + "RELEASE_TAG = \"v0.9.0\"\n", + "RELEASE_REF = \"338629cff2116952224ec60a98ac78b672f88ff6\"\n", "REPOSITORY = \"https://github.com/CellMigrationLab/morphobricks-preprocessing.git\"\n", "EXTRAS = \"notebook\"\n", "\n", diff --git a/notebooks/MorphoBricks_Preprocessing_Cellpose.ipynb b/notebooks/MorphoBricks_Preprocessing_Cellpose.ipynb index 225e65a9..34e6d175 100644 --- a/notebooks/MorphoBricks_Preprocessing_Cellpose.ipynb +++ b/notebooks/MorphoBricks_Preprocessing_Cellpose.ipynb @@ -91,12 +91,12 @@ "from urllib.request import url2pathname\n", "\n", "# LabConstrictor version identifiers.\n", - "current_version = \"0.8.0\"\n", + "current_version = \"0.9.0\"\n", "notebook_name = \"MorphoBricks_Preprocessing_Cellpose\"\n", "\n", "# A downloaded/Colab notebook installs this immutable source revision.\n", - "RELEASE_TAG = \"v0.8.0\"\n", - "RELEASE_REF = \"3af789160e9ce224a60da4582e9371f028ff47c5\"\n", + "RELEASE_TAG = \"v0.9.0\"\n", + "RELEASE_REF = \"338629cff2116952224ec60a98ac78b672f88ff6\"\n", "REPOSITORY = \"https://github.com/CellMigrationLab/morphobricks-preprocessing.git\"\n", "EXTRAS = \"notebook\"\n", "\n", diff --git a/notebooks/notebook_latest_versions.yaml b/notebooks/notebook_latest_versions.yaml index 1ee56047..5cd652cb 100644 --- a/notebooks/notebook_latest_versions.yaml +++ b/notebooks/notebook_latest_versions.yaml @@ -1,5 +1,5 @@ # Latest version of each notebook, read by LabConstrictor's version check by notebook_name. # Equal to the notebook's current_version and its RELEASE_TAG without the "v" (README, "Notebook"). -"MorphoBricks_Preprocessing": "0.8.0" +"MorphoBricks_Preprocessing": "0.9.0" "MorphoBricks_Cellpose": "0.1.0" -"MorphoBricks_Preprocessing_Cellpose": "0.8.0" +"MorphoBricks_Preprocessing_Cellpose": "0.9.0" diff --git a/pyproject.toml b/pyproject.toml index 35bf2bea..913f48ab 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "hatchling.build" [project] name = "morphobricks-preprocessing" -version = "0.8.0" +version = "0.9.0" description = "MorphoBricks preprocessing brick: per-plane intensity histograms and normalization methods for microscopy TIFFs." readme = "README.md" license = "MIT" diff --git a/src/morphobricks_preprocessing/notebook_cellpose.py b/src/morphobricks_preprocessing/notebook_cellpose.py index d9a8c452..e8dab93c 100644 --- a/src/morphobricks_preprocessing/notebook_cellpose.py +++ b/src/morphobricks_preprocessing/notebook_cellpose.py @@ -30,10 +30,10 @@ _card, ) from .notebook_cellpose_download import quiet_cellpose -from .notebook_cellpose_preview import MaskResult, preview_figures +from .notebook_cellpose_preview import MaskResult, preview_images from .notebook_progress import progress_html from .notebook_stop import CellStop -from .notebook_style import STYLE_CSS, table, tiles +from .notebook_style import STYLE_CSS, status, table, tiles from .run_inputs import Fov, RunInputs from .segmentation_cellpose_run import ( channel_layouts, @@ -117,15 +117,16 @@ def __init__(self) -> None: self.result: cp.BatchResult | None = None self.results: dict[str, cp.BatchResult] = {} self.previewed: list[MaskResult] = [] + self.preview_box = widgets.VBox() # the last Preview's result, and nothing else self.shown: list[str] = [] + self.styled = False # the style sheet is shown (once, by the first step or Preview) self.on_masks_written: Callable[[cp.BatchResult], object] | None = None self.register_with: str | None = None self.folders_refused = "" # the masks folder refusal of the last Open the run, or "" def _show(self, widget: widgets.Widget) -> None: """Display ``widget`` (the style sheet goes first, once).""" - if not self.shown: - display(widgets.HTML(STYLE_CSS)) + self._style() self.shown.append(getattr(widget, "value", "")) display(widget) @@ -147,6 +148,29 @@ def drop_choice(self) -> None: """Forget the channels, the mask types and every loaded model (the choice changed).""" self.picker = self.loaded = self.nuclei_loaded = self.nuclei_settings = None self.mask_types = {} + self.clear_preview() # a preview of other channels says nothing of the next ones + + def channels_edited(self) -> None: + """Take the preview off: a channel dropdown or number changed (Preview re-reads them).""" + self.clear_preview() + + def clear_preview(self) -> None: + """Take the last Preview's result off the screen and out of :attr:`previewed`.""" + self.previewed = [] + shown, self.preview_box.children = self.preview_box.children, () + for widget in shown: # their pictures leave the kernel too + widget.close() + + def _mount_preview(self) -> None: + """Show :attr:`preview_box` in the cell that previews (a form shows it on its page).""" + self._style() + display(self.preview_box) + + def _style(self) -> None: + """Display the style sheet, the first time only.""" + if not self.styled: + self.styled = True + display(widgets.HTML(STYLE_CSS)) def model_for(self, output: str) -> tuple[cp.LoadedModel, cp.Settings]: """Return the model and the settings that segment the masks of ``output``. @@ -237,6 +261,7 @@ def choose_channels( self.drop_choice() self.mask_types, self.mask_type = types, next(iter(types.values())) self.picker = ChannelPicker(self.inputs, output) + self.picker.on_edit(self.channels_edited) # the dropdowns are live: Preview re-reads them lines = tuple( f"{OUTPUT_NAMES[o]}, mask type {t}: {len(todo[o])} of {len(self.inputs.fovs())} " "images have no mask yet" @@ -258,7 +283,10 @@ def set_settings( Normalisation is not a choice: it is always Cellpose's own, per image (1st to 99th percentile of each channel). """ - self.settings = _settings(diameter, flow_threshold, cellprob_threshold, batch_size) + settings = _settings(diameter, flow_threshold, cellprob_threshold, batch_size) + if settings != self.settings: # a preview with other settings is taken off + self.clear_preview() + self.settings = settings @stops def set_nuclei_settings( @@ -270,7 +298,10 @@ def set_nuclei_settings( ) -> None: """Check the settings of a separate nuclei model (output Both, cell 5's Advanced).""" self._need_both() - self.nuclei_settings = _settings(diameter, flow_threshold, cellprob_threshold, batch_size) + settings = _settings(diameter, flow_threshold, cellprob_threshold, batch_size) + if settings != self.nuclei_settings: # a preview with other settings is taken off + self.clear_preview() + self.nuclei_settings = settings @stops def load( @@ -287,6 +318,7 @@ def load( if self.settings is None: raise SegmentationError("Set the settings first: press Load the model.") self.loaded = None + self.clear_preview() # a preview of the model loaded before is taken off self.loaded = self._load_model( model, custom_model_file, device, download_weights, install_dino, self.settings ) @@ -308,6 +340,7 @@ def load_nuclei( "step)." ) self.nuclei_loaded = None + self.clear_preview() # a preview of the nuclei model loaded before is taken off self.nuclei_loaded = self._load_model( model, custom_model_file, device, download_weights, install_dino, self.nuclei_settings ) @@ -324,6 +357,8 @@ def _need_both(self) -> None: def same_model_for_nuclei(self) -> None: """Segment the nuclei of Both with the model and the settings of the cells.""" + if self.nuclei_loaded is not None or self.nuclei_settings is not None: + self.clear_preview() # a preview of the nuclei's own model is taken off self.nuclei_loaded = self.nuclei_settings = None def _load_model( @@ -382,8 +417,21 @@ def _load_model( def preview(self, image: str = "") -> None: """Segment one image and show it with the outlines; nothing is written (cell 6). - For Both, the image is segmented twice, the cells and the nuclei, each shown. + For Both, the image is segmented twice, the cells and the nuclei, each shown. Every + result of an earlier Preview is taken off the screen first (:meth:`clear_preview`), and + a Preview that fails shows none: what is shown is always this Preview's result. While + Cellpose runs, one line says which model runs. """ + self.clear_preview() + self._mount_preview() + try: + self._preview(image) + except BaseException: # a refusal, any error or an interrupt: no result is shown + self.clear_preview() + raise + + def _preview(self, image: str) -> None: + """Segment ``image`` and put this Preview's result in :attr:`preview_box`.""" self._need("model") targets = self.picker.current_targets() fovs = self.inputs.fovs() @@ -395,24 +443,26 @@ def preview(self, image: str = "") -> None: ) fov = by_path[image.strip()] if image.strip() else (self.first_without_mask() or fovs[0]) check_manifest(self.inputs, self.run_manifest_sha256) # the run opened, still + models = [self.model_for(target.output) for target in targets] + names = " and ".join(dict.fromkeys(loaded.name for loaded, _ in models)) + running = status("info", f"Running {names} on the preview image…") + self.preview_box.children = (widgets.HTML(f"
{running}
"),) results, lines = [], [] - for target in targets: - loaded, settings = self.model_for(target.output) + for target, (loaded, settings) in zip(targets, models, strict=True): stack = target.plan.read(fov) labels, flows = cp.evaluate(loaded, settings, stack) named = tuple(zip(target.channel_ids, target.roles, strict=True)) result = MaskResult(OUTPUT_NAMES[target.output], stack, named, labels, flows) results.append(result) lines.append(f"{result.name}: {result.objects} objects; diameter {_diameter(settings)}") - self._show( - _card("info", f"Preview of {fov.relative_path} (nothing is written)", tuple(lines)) - ) + card = _card("info", f"Preview of {fov.relative_path} (nothing is written)", tuple(lines)) try: - figures = preview_figures(results) + pictures = preview_images(results) except ValueError as exc: raise SegmentationError(str(exc)) from exc - for figure in figures: - display(figure) + self.shown.append(card.value) + self.clear_preview() # the line of the model running + self.preview_box.children = (card, *pictures) self.previewed = results def first_without_mask(self) -> Fov | None: diff --git a/src/morphobricks_preprocessing/notebook_cellpose_channels.py b/src/morphobricks_preprocessing/notebook_cellpose_channels.py index 8a9ffb9d..053a6e76 100644 --- a/src/morphobricks_preprocessing/notebook_cellpose_channels.py +++ b/src/morphobricks_preprocessing/notebook_cellpose_channels.py @@ -9,6 +9,7 @@ from __future__ import annotations import html +from collections.abc import Callable from dataclasses import dataclass import ipywidgets as widgets @@ -205,6 +206,14 @@ def current_plan(self) -> SegmentationPlan: """ return self.current_targets()[0].plan + def on_edit(self, callback: Callable[[], object]) -> None: + """Call ``callback`` whenever a dropdown, a channel number or the By choice changes. + + Not when a step re-reads the choice (:meth:`current_targets`): only an edit. + """ + for field in (*self.dropdowns, *self.number_fields, self.by): + field.observe(lambda _: callback(), names="value") + def current_targets(self) -> tuple[MaskTarget, ...]: """Resolve the dropdowns as they are now and return every mask to make, or refuse. diff --git a/src/morphobricks_preprocessing/notebook_cellpose_form.py b/src/morphobricks_preprocessing/notebook_cellpose_form.py index 771abc56..5c1f22c1 100644 --- a/src/morphobricks_preprocessing/notebook_cellpose_form.py +++ b/src/morphobricks_preprocessing/notebook_cellpose_form.py @@ -293,6 +293,12 @@ def _drop_choice(self, fields: dict[str, widgets.Widget], changed: widgets.HTML) "warn", f"Changed: press Choose the channels again, then {then}." ) + def channels_edited(self) -> None: + """Take the preview off; Segment's line no longer says it used these channels.""" + super().channels_edited() + self._previewed_with = None + self._refresh_summary() + def drop_choice(self) -> None: """Forget the channels, the mask types and every loaded model (the choice changed).""" super().drop_choice() @@ -400,11 +406,28 @@ def preview_form(self) -> StepForm: cards, "Preview", "eye", - lambda: self._with_form_settings(lambda: self._preview_and_note(image.value or "")), + lambda: self._preview_from_form(image.value or ""), {"preview_image": image}, ) + # Under the button's output (the model's loading), the last Preview's result only. + form.body.children = [*form.body.children, self.preview_box] return self._keep("preview", form) + def _mount_preview(self) -> None: + """Show the preview's box in the cell, unless the Preview form already holds it.""" + if "preview" not in self.forms: + super()._mount_preview() + + def _preview_from_form(self, image: str) -> None: + """Press of **Preview**: take the last result off first, then load if needed and preview. + + Cleared before the model is checked or loaded, so a refused or failed load leaves no + earlier result on screen, nor the Segment step's line saying what it used. + """ + self.clear_preview() + self._previewed_with = None + self._with_form_settings(lambda: self._preview_and_note(image)) + def segment_form(self) -> StepForm: """Show the form of cell 7: overwrite (off by default) and the button that segments.""" overwrite = widgets.Checkbox(value=False, description="Replace masks that already exist") @@ -443,7 +466,11 @@ def _preview_and_note(self, image: str) -> None: self._refresh_summary() def _model_fields_changed(self) -> None: - """Update what shows the model form's values: Segment's line and the step strip.""" + """Take the preview off (Preview and Segment read these fields), then update the line. + + What the last Preview used is kept: Segment's line still says what changed since. + """ + self.clear_preview() self._refresh_summary() for callback in self.on_change: callback() diff --git a/src/morphobricks_preprocessing/notebook_cellpose_preview.py b/src/morphobricks_preprocessing/notebook_cellpose_preview.py index 2aa7c8a5..3a39533e 100644 --- a/src/morphobricks_preprocessing/notebook_cellpose_preview.py +++ b/src/morphobricks_preprocessing/notebook_cellpose_preview.py @@ -9,13 +9,20 @@ A preview holds a list of :class:`MaskResult`: one now, a cell mask or a nuclei mask; the *Both* output (#440) adds a second result and the figures follow, with no change here. + +The figures are shown as PNG pictures in widgets (:func:`preview_images`), never displayed into +an output area: the preview's box then holds the last Preview's result only, in every frontend +(owner, 26 November 2026: in Colab, nuclei figures of the first Preview stayed on screen after +later ones). """ from __future__ import annotations import importlib +import io from dataclasses import dataclass +import ipywidgets as widgets import numpy as np from matplotlib.figure import Figure @@ -90,3 +97,16 @@ def segmentation_figure(result: MaskResult) -> Figure: def preview_figures(results: list[MaskResult]) -> list[Figure]: """Return the preview's figures: the channels, then Cellpose's panels, for each result.""" return [figure for r in results for figure in (channel_figure(r), segmentation_figure(r))] + + +def figure_image(figure: Figure) -> widgets.Image: + """Return ``figure`` as a PNG picture widget, at most 99% of its box wide.""" + buffer = io.BytesIO() + figure.savefig(buffer, format="png", bbox_inches="tight") + layout = widgets.Layout(max_width="99%", height="auto") + return widgets.Image(value=buffer.getvalue(), format="png", layout=layout) + + +def preview_images(results: list[MaskResult]) -> list[widgets.Image]: + """Return the figures of :func:`preview_figures` as picture widgets, in the same order.""" + return [figure_image(figure) for figure in preview_figures(results)] diff --git a/tests/installed_record.py b/tests/installed_record.py index 85f3584b..5f2955f8 100644 --- a/tests/installed_record.py +++ b/tests/installed_record.py @@ -10,7 +10,7 @@ import json DISTRIBUTION = "morphobricks-preprocessing" -PINNED_VERSION = "0.8.0" +PINNED_VERSION = "0.9.0" """The version both notebooks' RELEASE_REF commits hold.""" diff --git a/tests/test_notebook_cellpose_preview_stale.py b/tests/test_notebook_cellpose_preview_stale.py new file mode 100644 index 00000000..b006149f --- /dev/null +++ b/tests/test_notebook_cellpose_preview_stale.py @@ -0,0 +1,218 @@ +"""Every Preview shows its own result only: nothing of an earlier Preview stays (owner, 26 Nov). + +The owner's Colab report: some nuclei results of the first Preview were not cleared after +pressing Preview several times. The result was displayed into the step's output area, and +its clearing was left to the frontend; a Preview that failed (the model, or its load) also +left the earlier result in ``previewed`` and the Segment step's line saying what "the last +Preview" used. The result is now held by one box of widgets (``workflow.preview_box``), +emptied before each Preview starts, before the model is loaded, and when the channels change; +a failed Preview leaves it empty. These cases drive ``segmentation_app`` headless with the +stand-in Cellpose (``tests/cellpose_stub.py``) on a run whose every image has DNA and TUB. +""" + +import ipywidgets as widgets +import pytest + +from cellpose_stub import install, two_channel_run +from morphobricks_preprocessing.notebook_cellpose_app import segmentation_app +from morphobricks_preprocessing.notebook_cellpose_channels import BY_NUMBER +from morphobricks_preprocessing.segmentation_record import record_path + + +@pytest.fixture +def stub(monkeypatch, tmp_path): + return install(monkeypatch, tmp_path) + + +@pytest.fixture +def run(tmp_path): + return two_channel_run(tmp_path / "run") + + +def walk(widget): + yield widget + for child in getattr(widget, "children", ()): + yield from walk(child) + + +def texts(widget): + return " ".join(str(w.value) for w in walk(widget) if isinstance(w, widgets.HTML)) + + +def pictures(widget): + return [w for w in walk(widget) if isinstance(w, widgets.Image)] + + +def choose(app, output): + form = app.workflow.forms["channels"] + form.fields["output"].value = output + form.button.click() + assert form.refusal == "", form.refusal + picker = app.workflow.picker + picker.cell.value = "TUB" + if output == "both": + picker.nuclear.value = "DNA" + + +def both_previewed(run): + """An app whose Preview showed the cells and the nuclei of Both once.""" + app = segmentation_app(run.out, run.masks) + choose(app, "both") + app.workflow.forms["model"].fields["device"].value = "cpu" + press_preview(app) + assert [r.name for r in app.workflow.previewed] == ["Cell mask", "Nuclei mask"] + assert "Segment will use what the last Preview used" in app.workflow._summary.value + return app + + +def press_preview(app): + form = app.workflow.forms["preview"] + form.submit() + assert form.refusal == "", form.refusal + return form + + +def snapshot(folder): + if not folder.exists(): + return None + return sorted((str(p.relative_to(folder)), p.stat().st_mtime_ns) for p in folder.rglob("*")) + + +def test_the_preview_page_holds_the_last_previews_result_only(run, stub): + app = both_previewed(run) + workflow = app.workflow + assert "Nuclei mask" in texts(workflow.preview_box) + page = app.stepper.pages[2] # Model and preview + assert sum(w is workflow.preview_box for w in walk(page)) == 1 + assert len(pictures(page)) == 4 # channels and Cellpose's panels, for cells and nuclei + workflow.forms["model"].fields["diameter"].value = "17" + press_preview(app) + shown = texts(workflow.preview_box) + assert shown.count("Preview of") == 1 and shown.count("Nuclei mask") == 1 + assert "diameter 17" in shown and len(pictures(page)) == 4 + + +def test_a_preview_of_cells_only_shows_no_nuclei_of_the_preview_of_both(run, stub): + app = both_previewed(run) + workflow = app.workflow + choose(app, "cells") # the output changed: the Both preview goes at once + assert workflow.previewed == [] + assert workflow.preview_box.children == () + press_preview(app) + assert [r.name for r in workflow.previewed] == ["Cell mask"] + assert "Nuclei" not in texts(workflow.preview_box) + assert len(pictures(workflow.preview_box)) == 2 + assert "Nuclei" not in texts(app.stepper.pages[2]) + + +def test_a_preview_whose_model_fails_leaves_no_earlier_result(run, stub): + app = both_previewed(run) + workflow = app.workflow + + def fail_nuclei(stack): + if stack.shape[0] == 1: + raise RuntimeError("out of memory") + + stub.fail = fail_nuclei + with pytest.raises(RuntimeError, match="out of memory"): # the output area shows it + workflow.forms["preview"].submit() + assert workflow.previewed == [] + assert "not previewed yet" in workflow._summary.value + assert workflow.preview_box.children == () + + +def test_a_preview_whose_model_does_not_load_leaves_no_earlier_result(run, stub): + app = both_previewed(run) + workflow = app.workflow + workflow.forms["model"].fields["device"].value = "cuda" # no GPU: the load is refused + form = workflow.forms["preview"] + form.submit() + assert form.refusal and workflow.loaded is None + assert workflow.previewed == [] + assert "not previewed yet" in workflow._summary.value + assert workflow.preview_box.children == () + + +def test_a_line_names_the_model_while_cellpose_runs_on_the_preview_image(run, stub): + app = segmentation_app(run.out, run.masks) + choose(app, "both") + model = app.workflow.forms["model"].fields + model["device"].value = "cpu" + model["separate_nuclei"].value, model["nuclei_model"].value = True, "cpsam" + seen = [] + stub.fail = lambda stack: seen.append(texts(app.workflow.preview_box)) + press_preview(app) + assert seen and all("on the preview image" in line for line in seen) + assert all("cpsam_v2 and cpsam" in line for line in seen) + assert "on the preview image" not in texts(app.workflow.preview_box) # replaced by the result + + +def test_previews_write_nothing(run, stub): + before = snapshot(run.masks) + app = both_previewed(run) + app.workflow.forms["model"].fields["diameter"].value = "17" + press_preview(app) + choose(app, "cells") + press_preview(app) + assert snapshot(run.masks) == before + assert app.workflow.results == {} and app.workflow.result is None + assert all(not record_path(run.masks, t).exists() for t in ("Cells", "Nuclei")) + + +# Review of #576: the channel dropdowns are live (Preview and Segment re-read them), and so are +# the model step's fields; any change takes the preview off, as a change of output does. + + +def test_removing_the_nuclear_channel_takes_the_preview_of_both_off(run, stub): + app = both_previewed(run) + workflow = app.workflow + workflow.picker.nuclear.value = "" + assert workflow.previewed == [] + assert workflow.preview_box.children == () + assert "Nuclei" not in texts(app.stepper.pages[2]) + assert "not previewed yet" in workflow._summary.value + + +def test_changing_the_cell_channel_takes_the_preview_off(run, stub): + app = both_previewed(run) + workflow = app.workflow + workflow.picker.cell.value = "DNA" + assert workflow.previewed == [] + assert workflow.preview_box.children == () + assert "not previewed yet" in workflow._summary.value + workflow.picker.cell.value = "TUB" + press_preview(app) # a new Preview shows its own result again + assert [r.name for r in workflow.previewed] == ["Cell mask", "Nuclei mask"] + + +def test_a_channel_number_takes_the_preview_off(run, stub): + app = both_previewed(run) + workflow = app.workflow + workflow.picker.by.value = BY_NUMBER + assert workflow.previewed == [] and workflow.preview_box.children == () + + +def test_changing_a_model_setting_takes_the_preview_off_and_names_the_change(run, stub): + app = both_previewed(run) + workflow = app.workflow + workflow.forms["model"].fields["diameter"].value = "17" + assert workflow.previewed == [] + assert workflow.preview_box.children == () + assert "Changed since the last Preview" in workflow._summary.value + + +def test_the_style_sheet_is_shown_once_after_a_failed_first_preview(run, stub, monkeypatch): + from morphobricks_preprocessing import notebook_cellpose + from morphobricks_preprocessing.notebook_style import STYLE_CSS + + sheets = [] + monkeypatch.setattr( + notebook_cellpose, + "display", + lambda w: sheets.append(w) if getattr(w, "value", None) == STYLE_CSS else None, + ) + workflow = notebook_cellpose.CellposeWorkflow() + workflow._mount_preview() # a first Preview, refused: no card shown + workflow._mount_preview() + workflow._show(widgets.HTML("a card")) + assert len(sheets) == 1 diff --git a/tests/test_notebook_file.py b/tests/test_notebook_file.py index 61fa76fe..0e5a6f19 100644 --- a/tests/test_notebook_file.py +++ b/tests/test_notebook_file.py @@ -138,6 +138,8 @@ def test_notebook_uses_stable_page_api_not_a_new_app_method(): "aa7ef1230b261531d06c3d5bafc0f933ca32beaf": "PreprocessingNotebook()", # v0.8.0: the same call. "438a2d37625ae7941953fa831914aa5ef5572696": "PreprocessingNotebook()", + # v0.9.0: the same call. + "338629cff2116952224ec60a98ac78b672f88ff6": "PreprocessingNotebook()", } CHECKOUT_CALL = "PreprocessingNotebook()" """The call of this checkout's code (every run described, no ``describe`` argument).""" diff --git a/tests/test_notebook_installed_commit.py b/tests/test_notebook_installed_commit.py index 7698eda4..20733e43 100644 --- a/tests/test_notebook_installed_commit.py +++ b/tests/test_notebook_installed_commit.py @@ -41,7 +41,7 @@ both notebooks.""" PINNED = f"morphobricks-preprocessing[notebook] @ git+{REPOSITORY}@{RELEASE_REF}" MAIN = "de3f7a476da8a3dc49c81b20935a9a1a4831a435" -"""A commit of main whose version is the release's, 0.8.0 (the #371 review's example).""" +"""A commit of main (the #371 review's example, then of the release's version, 0.8.0).""" def _functions(text, names): @@ -72,7 +72,7 @@ def test_setup_reuses_the_matching_installed_release(cell_1, capsys): # noqa: F "morphobricks_preprocessing.notebook_ui", # cell 3 shows it ] out = capsys.readouterr().out - assert "Ready: preprocessing 0.8.0" in out + assert "Ready: preprocessing 0.9.0" in out assert "ipywidgets 7.7.1" in out @@ -87,7 +87,7 @@ def test_setup_replaces_a_mismatched_installed_release(cell_1): # noqa: F811 def test_the_banner_shows_the_installed_commit(cell_1, capsys): # noqa: F811 state = cell_1 state.start(INSTALL) - assert f"Ready: preprocessing 0.8.0 (commit {RELEASE_REF});" in capsys.readouterr().out + assert f"Ready: preprocessing 0.9.0 (commit {RELEASE_REF});" in capsys.readouterr().out assert state.namespace["SETUP_RECORD"]["preprocessing_commit"] == RELEASE_REF assert state.namespace["SETUP_RECORD"]["source"] == "installed package" @@ -115,11 +115,11 @@ def test_the_banner_shows_the_installed_commit(cell_1, capsys): # noqa: F811 @pytest.mark.parametrize("record", NOT_THE_RELEASE.values(), ids=NOT_THE_RELEASE) def test_setup_installs_the_release_over_another_commit(cell_1, record, capsys): # noqa: F811 state = cell_1 - state.direct_url = record # the installed version is 0.8.0, as the notebook's + state.direct_url = record # the installed version is 0.9.0, as the notebook's state.start(INSTALL) forced_then_installed(state.installs, PINNED) # each is installed: pip would keep it out = capsys.readouterr().out - assert f"morphobricks-preprocessing v0.8.0 ({RELEASE_REF[:12]})" in out + assert f"morphobricks-preprocessing v0.9.0 ({RELEASE_REF[:12]})" in out assert f"(commit {RELEASE_REF})" in out # what pip installed, read again after it assert state.namespace["SETUP_RECORD"]["preprocessing_commit"] == RELEASE_REF @@ -133,14 +133,14 @@ def test_setup_stops_when_the_install_leaves_another_commit(cell_1, monkeypatch) forced_then_installed(state.installs, PINNED) assert state.namespace["SETUP_RECORD"] == {} # A restart would not help (pip kept the files): the stop gives the command that does. - assert f"recorded {'2' * 40}, not v0.8.0 ({RELEASE_REF})" in str(stop.value) + assert f"recorded {'2' * 40}, not v0.9.0 ({RELEASE_REF})" in str(stop.value) assert "Restart" not in str(stop.value) command = f'{sys.executable} -m pip install --force-reinstall --no-deps "{PINNED}"' assert f"Replace it with: {command}, then run this cell again." in str(stop.value) def test_setup_replaces_the_same_version_from_another_commit_that_pip_keeps(cell_1, capsys): # noqa: F811 - # The #371 review (pip 24.1.2 and 26.3): pip takes 0.8.0 from another commit as already + # The #371 review (pip 24.1.2 and 26.3): pip takes 0.9.0 from another commit as already # satisfied, installs nothing and keeps its record, so cell 1 stopped on every run. The # pinned commit is now forced, without its dependencies, then the extras are installed. state = cell_1 @@ -151,7 +151,7 @@ def test_setup_replaces_the_same_version_from_another_commit_that_pip_keeps(cell assert ( f"Replacing the installed morphobricks-preprocessing with commit {RELEASE_REF[:12]}" in out ) - assert f"Ready: preprocessing 0.8.0 (commit {RELEASE_REF});" in out + assert f"Ready: preprocessing 0.9.0 (commit {RELEASE_REF});" in out assert state.namespace["SETUP_RECORD"]["preprocessing_commit"] == RELEASE_REF state.start(INSTALL, fresh=False) assert len(state.installs) == 2 # running the cell again installs nothing more diff --git a/tests/test_notebook_setup.py b/tests/test_notebook_setup.py index f27b052c..12828e7c 100644 --- a/tests/test_notebook_setup.py +++ b/tests/test_notebook_setup.py @@ -109,7 +109,7 @@ def setup_environment(tmp_path, monkeypatch): drive=tmp_path / "content/drive", namespace={}, versions={ - "morphobricks-preprocessing": "0.8.0", + "morphobricks-preprocessing": "0.9.0", "morphobricks-normalization": "0.8.0", "ipywidgets": "7.7.1", }, @@ -172,7 +172,7 @@ def checkout_at(path): package.mkdir(parents=True) (package / "__init__.py").write_text("", encoding="utf-8") (path / "pyproject.toml").write_text( - '[project]\nname = "morphobricks-preprocessing"\nversion = "0.8.0"\n', + '[project]\nname = "morphobricks-preprocessing"\nversion = "0.9.0"\n', encoding="utf-8", ) return path @@ -188,8 +188,8 @@ def test_setup_installs_missing_package_from_the_exact_commit(setup_environment, target = command[5] assert target.startswith("morphobricks-preprocessing[notebook] @ git+") assert target.endswith("@" + namespace["RELEASE_REF"]) - assert namespace["RELEASE_REF"] == "438a2d37625ae7941953fa831914aa5ef5572696" - assert "pinned v0.8.0 candidate" in capsys.readouterr().out + assert namespace["RELEASE_REF"] == "338629cff2116952224ec60a98ac78b672f88ff6" + assert "pinned v0.9.0 candidate" in capsys.readouterr().out def test_setup_prefers_a_nearby_checkout(setup_environment, tmp_path, monkeypatch, capsys): @@ -272,7 +272,7 @@ def test_an_explicit_development_override_uses_the_checkout_and_says_so( assert sys.path[0] == str(checkout / "src") assert f"commit {OTHER_COMMIT}, uncommitted changes" in out assert "DEVELOPMENT OVERRIDE is on" in out - assert "DEVELOPMENT OVERRIDE on" in out.split("Notebook 0.8.0")[1] + assert "DEVELOPMENT OVERRIDE on" in out.split("Notebook 0.9.0")[1] record = namespace["SETUP_RECORD"] assert record["checkout_commit"] == OTHER_COMMIT assert record["checkout_has_uncommitted_changes"] is True @@ -416,7 +416,7 @@ def test_cell_1_installs_without_mounting_drive_or_showing_the_app( assert namespace["SETUP_RECORD"]["release_ref"] == RELEASE_REF out = capsys.readouterr().out assert ( - f"Ready: preprocessing 0.8.0 (commit {RELEASE_REF}); normalization 0.8.0; " + f"Ready: preprocessing 0.9.0 (commit {RELEASE_REF}); normalization 0.8.0; " "ipywidgets 7.7.1." in out ) assert "Next: run cell 2 (Mount Google Drive), then cell 3 (Run preprocessing)." in out @@ -434,8 +434,8 @@ def test_running_cell_1_again_installs_nothing_more(setup_environment, capsys): assert len(state.installs) == 1 assert "Installing notebook requirements" in first assert "Installing notebook requirements" not in again - assert "Ready: preprocessing 0.8.0" in again - assert state.namespace["SETUP_RECORD"]["preprocessing_version"] == "0.8.0" + assert "Ready: preprocessing 0.9.0" in again + assert state.namespace["SETUP_RECORD"]["preprocessing_version"] == "0.9.0" assert record["release_ref"] == state.namespace["SETUP_RECORD"]["release_ref"] diff --git a/tests/test_segmentation_case_folder.py b/tests/test_segmentation_case_folder.py index c15489b8..78752841 100644 --- a/tests/test_segmentation_case_folder.py +++ b/tests/test_segmentation_case_folder.py @@ -74,6 +74,8 @@ def test_a_file_differing_only_in_case_is_refused_too(tmp_path): def test_both_spellings_present_are_refused_even_for_the_exact_one(tmp_path): (tmp_path / "Cells").mkdir() + if (tmp_path / "cells").is_dir(): # macOS, Windows: the same folder + pytest.skip("this file system ignores case: both spellings cannot exist") (tmp_path / "cells").mkdir() # only possible where case counts (Linux) with pytest.raises(SegmentationError, match=CODE): check_mask_type_folder(tmp_path, "Cells")