Skip to content

ADR-002: Extract openptv2.pipeline and openptv2.config from gui/

Status: Accepted Date: 2026-11-29 Author: architecture review

Context

src/openptv2/gui/ptv.py (1,983 lines) is the de facto headless pipeline: it holds the sequence loop, the stage functions (py_start_proc_c, …), image reading, parameter population, store opening, and legacy conversion. It imports no GUI libraries at module level, but openptv2.gui.__init__ imports traits, so importing openptv2.gui.ptv pulls the whole GUI dependency graph. Every caller that needs the pipeline — batch, CLI, plugins, algorithms, autocalibration, recorrespond — imports it through gui/.

The same is true of gui/experiment.py and the gui/parameter_* modules: they are configuration, not widgets.

This violates the intended layering (gui / batch / cli → plugins → tracking → algorithms → storage) and makes "the headless library imports the GUI" a true statement.

Decision

  1. Create openptv2.pipeline/ containing the sequence loop, stages, image I/O, store opening and parameter population moved out of gui/ptv.py. Create openptv2.config/ containing experiment.py and the parameter_* modules. After this, gui/ contains only widget modules; algorithms and storage never import gui.

  2. No TrackingContext type. Plugins keep the two-argument contract Tracking(pipeline=<module>, exp=<object>) / Sequence(pipeline=..., exp=...). The pipeline module is the context a plugin sees; a context dataclass would be an abstraction without a concrete need (simplicity before sophistication). A context type can be introduced later if a plugin needs a narrower surface.

  3. Public entry point: openptv2.pipeline.run(exp) -> RunStore | None. exp is an Experiment (or any object with pm / exp1.pm). Returns the RunStore written to, or None when there is no store.

  4. Module split during the move: split only the already-separate concerns into pipeline/images.py, pipeline/store.py, pipeline/params.py; keep the sequence loop and stages in pipeline/loop.py. Do not combine this with splitting the god modules — that is a separate ticket.

  5. Compatibility: keep openptv2.gui.ptv, openptv2.gui.experiment, openptv2.gui.parameter_* as deprecated shims for one release via module-level __getattr__ forwarding with a one-time DeprecationWarning. Internal imports and tests switch to the new paths in the same commit.

  6. Migration is staged: (1) add pipeline/ + config/ as copies with shims; (2) switch internal imports; (3) delete the gui/ originals. Each step is a green test run.

Consequences

  • gui/ becomes widget-only; import openptv2.pipeline no longer loads Traits.
  • algorithms/parameter_converters.py can import openptv2.config.parameter_defaults instead of openptv2.gui.parameter_defaults, removing the last algorithms → gui edge.
  • Plugins are testable with pipeline=openptv2.pipeline and a fake/real experiment, without a fake GUI module.
  • The public surface gains one function (run) and one module (pipeline); everything else stays internal.
  • Cost: a staged, mechanical move of ~4,600 lines plus import rewrites and test updates. No algorithm changes.

Alternatives considered

  • A TrackingContext dataclass (rejected for now): would narrow the plugin surface, but plugins already receive exactly what they use through pipeline + exp; inventing a context type adds a layer with no concrete driver.
  • Moving ptv.py unchanged as one module (rejected): relocates the god module without improving readability.
  • Hard break, no shims (rejected): the repo already maintains pyptv compatibility; a one-release shim costs ~20 lines.
  • run(config) with a new config dataclass (deferred to Candidate 2): would couple this change to the parameter-schema work.
  • Candidate 4 of the 2026-11-29 architecture review.
  • docs/developer_guide/pipeline-migration.md — file-by-file migration plan.
  • docs/course/glossary.md — user-facing glossary; GLOSSARY.md — developer glossary.