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¶
-
Create
openptv2.pipeline/containing the sequence loop, stages, image I/O, store opening and parameter population moved out ofgui/ptv.py. Createopenptv2.config/containingexperiment.pyand theparameter_*modules. After this,gui/contains only widget modules;algorithmsandstoragenever importgui. -
No
TrackingContexttype. Plugins keep the two-argument contractTracking(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. -
Public entry point:
openptv2.pipeline.run(exp) -> RunStore | None.expis anExperiment(or any object withpm/exp1.pm). Returns theRunStorewritten to, orNonewhen there is no store. -
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 inpipeline/loop.py. Do not combine this with splitting the god modules — that is a separate ticket. -
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-timeDeprecationWarning. Internal imports and tests switch to the new paths in the same commit. -
Migration is staged: (1) add
pipeline/+config/as copies with shims; (2) switch internal imports; (3) delete thegui/originals. Each step is a green test run.
Consequences¶
gui/becomes widget-only;import openptv2.pipelineno longer loads Traits.algorithms/parameter_converters.pycan importopenptv2.config.parameter_defaultsinstead ofopenptv2.gui.parameter_defaults, removing the lastalgorithms → guiedge.- Plugins are testable with
pipeline=openptv2.pipelineand 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
TrackingContextdataclass (rejected for now): would narrow the plugin surface, but plugins already receive exactly what they use throughpipeline+exp; inventing a context type adds a layer with no concrete driver. - Moving
ptv.pyunchanged as one module (rejected): relocates the god module without improving readability. - Hard break, no shims (rejected): the repo already maintains
pyptvcompatibility; 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.
Related¶
- 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.