vernier.adapters
Drop-in shims for migrating from competing tools without rewriting the
call sites. Today: a pycocotools COCOeval adapter; future shims slot
in here.
Framework adapters for vernier.
This subpackage holds optional integrations with external frameworks
(PyTorch tensors via DLPack, etc.) and migration helpers. Each adapter
is importable without its underlying framework being installed; gate
framework-specific imports behind try/except ImportError.
The pycocotools migration helper (:func:patch_pycocotools) is the
sanctioned entry point for swapping
pycocotools.cocoeval.COCOeval with vernier's drop-in. Policy and
rationale are in ADR-0007.
patch_pycocotools
patch_pycocotools(
parity_mode: ParityMode = "strict",
) -> Callable[[], None]
Replace pycocotools.cocoeval.COCOeval with vernier's drop-in.
Returns an idempotent unpatch callable. The outermost unpatch
restores the original pycocotools class; intermediate unpatches
pop the parity-mode stack so nested
:func:patched_pycocotools exits restore the surrounding patch
state. Per ADR-0007:
- Default
parity_modeis"strict"because migration intent is bit-exactness with pycocotools. - Raises :class:
ImportErrorif pycocotools is not installed — silent fallthrough would let downstream test setups think the patch took effect when it did not. - Calling
patch_pycocotoolsrepeatedly without unpatching stacks the parity-mode state but never overwrites the saved original class, so the final unpatch always restores the real pycocotools class.
Not thread-safe — call once at process or test setup, unwind at
teardown. The patch must fire before any module that imports
pycocotools.cocoeval — see docs/migrate/from-pycocotools.md
§"Troubleshooting" for the import-order pitfall and the
session-scoped pytest fixture that side-steps it.
patched_pycocotools
patched_pycocotools(
parity_mode: ParityMode = "strict",
) -> Generator[None, None, None]
Context-manager variant of :func:patch_pycocotools.
Nests correctly: an outer with followed by an inner with
restores the outer-patch state on inner exit and the original
pycocotools class on outer exit (per ADR-0007 §"Reentrancy").