refactor(api): trailing newlines + hoist acks.py parser imports to top-level
Self-review nits from the router-split commit: - All four new files lacked a trailing newline (PEP 8 / POSIX). - acks.py was lazily importing ParseResult999 / serialize_999 inside get_ack_endpoint. Hoist to module-level — there's no import cycle (acks.py does not import from cyclone.api), so the imports are safe to do once. No behavior change. Targeted tests (test_acks + test_health + test_api_gets) still pass 41/41.
This commit is contained in:
@@ -1 +1 @@
|
|||||||
"""Resource-group routers. Imported and registered by ``cyclone.api``."""
|
"""Resource-group routers. Imported and registered by ``cyclone.api``."""
|
||||||
|
|||||||
@@ -17,6 +17,8 @@ from fastapi import APIRouter, HTTPException, Query, Request
|
|||||||
from fastapi.responses import StreamingResponse
|
from fastapi.responses import StreamingResponse
|
||||||
|
|
||||||
from cyclone.api_helpers import ndjson_stream_list, wants_ndjson
|
from cyclone.api_helpers import ndjson_stream_list, wants_ndjson
|
||||||
|
from cyclone.parsers.models_999 import ParseResult999
|
||||||
|
from cyclone.parsers.serialize_999 import serialize_999
|
||||||
from cyclone.store import store
|
from cyclone.store import store
|
||||||
|
|
||||||
router = APIRouter()
|
router = APIRouter()
|
||||||
@@ -91,8 +93,6 @@ def get_ack_endpoint(ack_id: int) -> dict:
|
|||||||
# the regenerated text to keep payloads small; detail does.)
|
# the regenerated text to keep payloads small; detail does.)
|
||||||
if row.raw_json:
|
if row.raw_json:
|
||||||
try:
|
try:
|
||||||
from cyclone.parsers.models_999 import ParseResult999
|
|
||||||
from cyclone.parsers.serialize_999 import serialize_999
|
|
||||||
regenerated = ParseResult999.model_validate(row.raw_json)
|
regenerated = ParseResult999.model_validate(row.raw_json)
|
||||||
icn = regenerated.envelope.control_number or "000000001"
|
icn = regenerated.envelope.control_number or "000000001"
|
||||||
body["raw_999_text"] = serialize_999(regenerated, interchange_control_number=icn)
|
body["raw_999_text"] = serialize_999(regenerated, interchange_control_number=icn)
|
||||||
@@ -101,4 +101,4 @@ def get_ack_endpoint(ack_id: int) -> dict:
|
|||||||
body["raw_999_text"] = None
|
body["raw_999_text"] = None
|
||||||
else:
|
else:
|
||||||
body["raw_999_text"] = None
|
body["raw_999_text"] = None
|
||||||
return body
|
return body
|
||||||
|
|||||||
@@ -14,4 +14,4 @@ router = APIRouter()
|
|||||||
|
|
||||||
@router.get("/api/health")
|
@router.get("/api/health")
|
||||||
def health() -> dict[str, str]:
|
def health() -> dict[str, str]:
|
||||||
return {"status": "ok", "version": __version__}
|
return {"status": "ok", "version": __version__}
|
||||||
|
|||||||
@@ -73,4 +73,4 @@ def get_ta1_ack_endpoint(ack_id: int) -> dict:
|
|||||||
body = _ta1_to_ui(row)
|
body = _ta1_to_ui(row)
|
||||||
body["raw_ta1_text"] = _serialize_ta1_from_row(row)
|
body["raw_ta1_text"] = _serialize_ta1_from_row(row)
|
||||||
body["raw_json"] = row.raw_json
|
body["raw_json"] = row.raw_json
|
||||||
return body
|
return body
|
||||||
|
|||||||
Reference in New Issue
Block a user