Skip to content

im_info: add DROPPABLE_KEYS + presets + remove_marked_intermediates (Slice 1 of #245)#250

Merged
aelefebv merged 1 commit into
dechaofrom
slice-1-im-info-droppable-keys
May 12, 2026
Merged

im_info: add DROPPABLE_KEYS + presets + remove_marked_intermediates (Slice 1 of #245)#250
aelefebv merged 1 commit into
dechaofrom
slice-1-im-info-droppable-keys

Conversation

@aelefebv

Copy link
Copy Markdown
Owner

Summary

  • Adds module-level constants in nellie.im_info: DROPPABLE_KEYS (the 14-key universe), KEEP_EVERYTHING_PRESET, MASKS_AND_CSVS_PRESET, CSVS_ONLY_PRESET.
  • Adds ImInfo.remove_marked_intermediates(drop_keys: frozenset[str]) — validates against DROPPABLE_KEYS, deletes only the marked files, silently skips missing ones.
  • Refactors legacy ImInfo.remove_intermediates() into a one-line shim calling the new method with DROPPABLE_KEYS. Both pre-existing pinned tests pass unchanged.
  • 11 new tests in tests/test_verifier_iminfo.py (section H.1) pin the contract.
  • ADR 0014 written and indexed: wiki/decisions/0014-intermediates-policy-frozenset.md.

Closes #246. Foundation for Slices 2/3 of #245.

Test plan

  • uv run pytest tests/test_verifier_iminfo.py -q — 68 passed (was 57, 11 new)
  • Reviewer: confirm DROPPABLE_KEYS membership matches _create_output_paths (every non-CSV key plus im_path)
  • Reviewer: confirm legacy remove_intermediates() semantics preserved end-to-end

🤖 Generated with Claude Code

…Slice 1 of #245)

Foundation for per-output intermediate retention. Adds module-level
``DROPPABLE_KEYS`` (the 14-key universe of toggleable outputs: 12
image-like intermediates + ``adjacency_maps`` + the special
``im_path``), three preset constants
(``KEEP_EVERYTHING_PRESET``, ``MASKS_AND_CSVS_PRESET``,
``CSVS_ONLY_PRESET``), and a new method
``ImInfo.remove_marked_intermediates(drop_keys)`` that validates
the input against ``DROPPABLE_KEYS`` and deletes only the marked
files (silently skipping any that were never produced).

Legacy ``ImInfo.remove_intermediates()`` is refactored into a
one-line shim calling
``remove_marked_intermediates(drop_keys=DROPPABLE_KEYS)``;
the two pre-existing pinned tests
(``test_remove_intermediates_preserves_csv_files``,
``test_remove_intermediates_deletes_canonical_im_path``) continue
to pass unchanged.

11 new tests in ``tests/test_verifier_iminfo.py`` (section H.1)
pin: ``DROPPABLE_KEYS`` membership exact (no CSVs); each preset's
membership; per-key drop semantics; empty drop set is a no-op;
unknown / CSV keys raise ``AssertionError``; missing files are
silently skipped; ``im_path`` resolves correctly; legacy shim
matches the new method.

ADR 0014 documents the API-shape decision (``frozenset[str]``
over a structured dataclass).

Closes #246

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@aelefebv
aelefebv merged commit 87e96bc into dechao May 12, 2026
6 checks passed
@aelefebv
aelefebv deleted the slice-1-im-info-droppable-keys branch May 12, 2026 20:47
aelefebv added a commit that referenced this pull request May 12, 2026
… Qt importorskip + wiki close-out (#245) (#254)

CI fixes for the per-output retention slices (PRs #250-#253):

1. **Windows mmap-release** in
   ``ImInfo.remove_marked_intermediates``. The post-rewrite method
   tried to ``os.remove(im_path)`` while ``self.im`` still held the
   tifffile memmap, triggering ``PermissionError [WinError 32] The
   process cannot access the file because it is being used by
   another process`` on Windows CI. Fix: drop ``self.im`` (and
   ``gc.collect()``) at the start of the method — the existing
   pattern documented at ``_release_iminfo_memmap`` in
   ``test_verifier_iminfo.py``. Always-release is the cheapest
   and safest default; any pipeline intermediate could be
   memmap'd by a stage that's still alive in the process. Callers
   who use ``info.im`` after cleanup get ``None`` (correct — the
   file may be gone).

2. **Ubuntu headless Qt** ImportError on ``libEGL.so.1`` for
   ``test_napari_settings.py``. ``qtpy.QtWidgets`` transitively
   pulls Qt's display libs even for the dataclass-only tests
   (``SettingsConfig`` lives in the same module). Fix: module-level
   ``pytest.importorskip("qtpy.QtWidgets")`` so the entire file
   skips cleanly on systems without Qt's display libs. Tests pass
   normally where Qt loads.

Phase 5 wiki close-out for PRD #245:

- ``wiki/glossary.md`` — new ``DROPPABLE_KEYS`` entry pointing to
  [[decisions/0014-intermediates-policy-frozenset]].
- ``wiki/pipeline.md`` Gotchas — new bullet for the per-output
  cleanup mechanism: end-of-pipeline-only, only-on-success
  (inherits the existing "no try/except around stages" gotcha),
  ``cleanup_drop_keys`` kwarg surface.
- ``wiki/im-info.md`` test-coverage line — updated to call out
  ``remove_marked_intermediates`` + ``DROPPABLE_KEYS`` /
  preset-constants alongside the legacy ``remove_intermediates``
  shim. Test count bumped (~57 → ~68).
- ``wiki/now.md`` — "Active work" cleared; "Recently shipped"
  entry summarizes the four-slice chain, the API surface, the
  failure semantics, the test count delta (715 → 748 non-perf),
  and the new ADR.

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.

1 participant