Source code for cadrumo.entrypoints.tui.modelo.routes
"""The closed route table for the Modelo workspace read destinations.This is a FIRST CONSTRUCTION, not a migration. No route registry existedbefore it: the TUI had no route ids, no destination table and no factorymap, and destinations were reached by a CLI handler importing a screendirectly. So the census this module supports is derived from what itBUILDS -- every declared destination resolves to exactly one factory, andevery factory answers exactly one declared destination -- and neverasserted as "zero remaining" over a structure that never had entries toremove.The destination identities come from:data:`ModeloWorkspaceDestinationIdV1` rather than being restated here.That alias is the single definition of the closed set, so a destinationcannot be routed that no view model can address, and the completenesscheck below compares this table against the alias rather than against acopy of it. A hand-listed census would agree with itself.Factories take an admitted :class:`ModeloWorkspaceReadSession` and returna screen. They resolve nothing: admission has already happened by the timea route is taken, and a factory that re-resolved would give a destinationa different read from the one the operator navigated within."""from__future__importannotationsfromcollections.abcimportCallablefromtypingimportFinal,get_argsfromtextual.screenimportScreenfrom.view.controllerimportModeloWorkspaceReadSessionfrom.view.filingimportModeloWorkspaceFilingScreenfrom.view.inputsimportModeloWorkspaceInputsScreenfrom.view.modelsimportModeloWorkspaceDestinationIdV1from.view.overviewimportModeloWorkspaceOverviewScreenfrom.view.provenanceimportModeloWorkspaceProvenanceScreenfrom.view.resultsimportModeloWorkspaceResultsScreenfrom.view.verificationimportModeloWorkspaceVerificationScreentypeModeloWorkspaceDestinationFactoryV1=Callable[[ModeloWorkspaceReadSession],Screen[None]]"""Builds one destination's screen from an already-admitted session."""MODELO_WORKSPACE_DESTINATIONS:Final[dict[ModeloWorkspaceDestinationIdV1,ModeloWorkspaceDestinationFactoryV1]]={"modelo.workspace.overview":ModeloWorkspaceOverviewScreen,"modelo.workspace.inputs":ModeloWorkspaceInputsScreen,"modelo.workspace.results":ModeloWorkspaceResultsScreen,"modelo.workspace.provenance":ModeloWorkspaceProvenanceScreen,"modelo.workspace.verification":ModeloWorkspaceVerificationScreen,"modelo.workspace.filing":ModeloWorkspaceFilingScreen,}"""Every read destination, keyed by its route identity.The C1 selection outcome is ``modelo.workspace.overview``: a picker thathas resolved a work unit hands the operator the workspace frame, not thebounded review screen it used to reach."""WORKSPACE_SELECTION_OUTCOME:Final[ModeloWorkspaceDestinationIdV1]="modelo.workspace.overview""""The destination a completed work-unit selection lands on.Named rather than inlined at the call site so the selection outcome hasone definition. A launcher that hardcoded a screen class would make theoutcome a property of whichever CLI module happened to import it."""
[docs]defdeclared_destination_ids()->frozenset[str]:"""Return the closed destination set, read from its own type alias. Read from ``get_args`` rather than restated, so this cannot drift from the alias the view models address. A literal copy here would be a second definition that agrees with the first only until someone edits one of them. """destinations:set[str]=set()forargumentinget_args(ModeloWorkspaceDestinationIdV1.__value__):ifnotisinstance(argument,str):message=f"destination alias must hold only string literals, found {argument!r}"raiseTypeError(message)destinations.add(argument)returnfrozenset(destinations)
def_require_total_destination_table()->None:"""Refuse a table that does not answer every declared destination exactly once."""routed=frozenset(MODELO_WORKSPACE_DESTINATIONS)declared=declared_destination_ids()ifrouted!=declared:missing=sorted(declared-routed)extra=sorted(routed-declared)raiseValueError(f"workspace destination table must cover each declared id exactly once: {missing=}{extra=}")iflen(set(MODELO_WORKSPACE_DESTINATIONS.values()))!=len(MODELO_WORKSPACE_DESTINATIONS):raiseValueError("each workspace destination must resolve to its own factory")_require_total_destination_table()
[docs]defresolve_destination(destination:ModeloWorkspaceDestinationIdV1)->ModeloWorkspaceDestinationFactoryV1:"""Return the one factory registered for this destination identity."""returnMODELO_WORKSPACE_DESTINATIONS[destination]