C1a: code only, no comments, no Markdown

Remove 64 Python docstrings and 39 comments, and trim prose from three noqa pragmas. The submodule had zero tracked Markdown files.

Move published route descriptions into decorator arguments and the Correction schema description into ConfigDict. Drop internal docstrings, including the OAuth callback excluded from OpenAPI. Published route descriptions are unchanged in the before-and-after comparison of the nine application routers. The full application OpenAPI check requires fastapi-users, which is missing from the shared environment.
This commit is contained in:
2026-12-01 16:55:32 -06:00
parent 37c456c5ef
commit c326f4901d
13 changed files with 284 additions and 207 deletions
+43 -23
View File
@@ -1,5 +1,3 @@
"""/conectar: look into a site's sources, draw and save pipelines, run them, inspect nodes."""
from typing import Annotated, Any
from dagster_graphql import DagsterGraphQLClient, DagsterGraphQLClientError
@@ -22,22 +20,26 @@ Rows = list[dict[str, Any]]
def _from_source(call, *args):
try:
return call(*args)
except Exception as e: # noqa: BLE001 - the operator needs the source's own message
except Exception as e: # noqa: BLE001
raise HTTPException(422, detail=f"{type(e).__name__}: {e}") from e
@router.get("/schema")
@router.get(
"/schema",
description="What the canvas draws with: every node kind's form, and the platform entities.",
)
def schema() -> dict[str, Any]:
"""What the canvas draws with: every node kind's form, and the platform entities."""
return {
"pipeline": Pipeline.model_json_schema(),
"entities": {name: model.model_json_schema() for name, model in ENTITIES.items()},
}
@router.post("/sources/preview")
@router.post(
"/sources/preview",
description="The first rows a source node would load.",
)
def source_preview(node: Source, limit: Annotated[int, Query(ge=1, le=200)] = 20) -> Rows:
"""The first rows a source node would load."""
return [nodes.shown(r) for r in _from_source(nodes.preview, node, limit)]
@@ -51,19 +53,26 @@ class SavedPipeline(BaseModel):
pipeline: Pipeline
@router.get("/pipelines/{pipeline_id}")
@router.get(
"/pipelines/{pipeline_id}",
description="A saved pipeline (latest by default), with its secrets masked.",
)
def pipeline(pipeline_id: PipelineId, version: int | None = None) -> SavedPipeline:
"""A saved pipeline (latest by default), with its secrets masked."""
if not config_log.latest_version(pipeline_id):
raise HTTPException(404, detail=f"no pipeline {pipeline_id}")
found, saved = config_log.get(pipeline_id, version)
return SavedPipeline(version=found, pipeline=redacted(saved))
@router.put("/pipelines/{pipeline_id}")
@router.put(
"/pipelines/{pipeline_id}",
description=(
"Saves a new version. Masked secrets sent back are kept as they "
"were saved; every\n"
"ConceptMap a node names must exist."
),
)
def save_pipeline(pipeline_id: PipelineId, drawn: Pipeline) -> dict[str, int]:
"""Saves a new version. Masked secrets sent back are kept as they were saved; every
ConceptMap a node names must exist."""
named = {n.concept_map for n in drawn.nodes if getattr(n, "concept_map", None)}
if missing := sorted(m for m in named if not config_log.latest_version(m, "concept_maps")):
raise HTTPException(422, detail=f"no concept maps {missing}")
@@ -75,18 +84,26 @@ def save_pipeline(pipeline_id: PipelineId, drawn: Pipeline) -> dict[str, int]:
return {"version": config_log.save(pipeline_id, complete)}
@router.get("/concept-maps/{map_id}")
@router.get(
"/concept-maps/{map_id}",
description="A site's codes in platform terms (FHIR R4B ConceptMap), latest version.",
)
def get_concept_map(map_id: PipelineId) -> dict[str, Any]:
"""A site's codes in platform terms (FHIR R4B ConceptMap), latest version."""
if not config_log.latest_version(map_id, "concept_maps"):
raise HTTPException(404, detail=f"no concept map {map_id}")
return config_log.concept_map(map_id).model_dump(mode="json", exclude_none=True)
@router.put("/concept-maps/{map_id}")
@router.put(
"/concept-maps/{map_id}",
description=(
"Saves a new version of a ConceptMap. Its groups target the "
"systems platform fields\n"
"take codes from, and only codes those fields allow "
"(core.concept_map)."
),
)
def save_concept_map(map_id: PipelineId, doc: dict[str, Any]) -> dict[str, int]:
"""Saves a new version of a ConceptMap. Its groups target the systems platform fields
take codes from, and only codes those fields allow (core.concept_map)."""
try:
found = ConceptMap.model_validate({**doc, "resourceType": "ConceptMap"})
except ValueError as e:
@@ -97,23 +114,24 @@ def save_concept_map(map_id: PipelineId, doc: dict[str, Any]) -> dict[str, int]:
class RunRequest(BaseModel):
version: int | None = None # default: the latest saved
version: int | None = None
@router.post("/pipelines/{pipeline_id}/runs")
@router.post(
"/pipelines/{pipeline_id}/runs",
description="Starts the `ingest` job for this pipeline; follow it at /runs/{run_id}.",
)
def start_run(
pipeline_id: PipelineId,
request: RunRequest,
client: DagsterGraphQLClient = Depends(dagster),
) -> dict[str, str]:
"""Starts the `ingest` job for this pipeline; follow it at /runs/{run_id}."""
if not config_log.latest_version(pipeline_id):
raise HTTPException(404, detail=f"no pipeline {pipeline_id}")
return {"run_id": submit(client, pipeline_id, request.version)}
def submit(client: DagsterGraphQLClient, pipeline_id: str, version: int | None = None) -> str:
"""Starts the `ingest` job for a saved pipeline (the latest version by default)."""
config = {"pipeline": pipeline_id, "version": version}
try:
return client.submit_job_execution(
@@ -123,13 +141,15 @@ def submit(client: DagsterGraphQLClient, pipeline_id: str, version: int | None =
raise HTTPException(502, detail=str(e)) from e
@router.get("/pipelines/{pipeline_id}/nodes/{node_id}/rows")
@router.get(
"/pipelines/{pipeline_id}/nodes/{node_id}/rows",
description="What a node produced in the last run (empty if it produced nothing yet).",
)
def node_rows(
pipeline_id: PipelineId,
node_id: NodeId,
limit: Annotated[int, Query(ge=1, le=500)] = 50,
) -> Rows:
"""What a node produced in the last run (empty if it produced nothing yet)."""
out = []
for row in nodes.rows(pipeline_id, node_id):
out.append(nodes.shown(row))