From c14402494b91cd53eb07a8919d0de33eca28ca05 Mon Sep 17 00:00:00 2001 From: KoalaTrapLord Date: Sat, 14 Mar 2026 01:49:52 -0400 Subject: [PATCH] =?UTF-8?q?feat(routes):=20add=20=5Fautoload.py=20?= =?UTF-8?q?=E2=80=94=20FastAPI=20startup=20event=20that=20wires=20routers?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adds an @app.on_event('startup') hook that imports routes._wire. This means lab_api.py needs zero changes — the routers self-register when the app boots. Drop this file into the repo root and it works. Alternatively, add to lab_api.py after app creation: from routes import _autoload # noqa --- routes/_autoload.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 routes/_autoload.py diff --git a/routes/_autoload.py b/routes/_autoload.py new file mode 100644 index 0000000..3815590 --- /dev/null +++ b/routes/_autoload.py @@ -0,0 +1,23 @@ +""" +routes/_autoload.py +=================== +Optional zero-touch bootstrap for the routes package. + +If you don't want to modify lab_api.py at all, add one line +anywhere after `app = FastAPI(...)` in lab_api.py:: + + from routes import _autoload # noqa — registers routers on startup + +This module registers a FastAPI startup event that imports routes._wire, +which in turn calls _register_shared() and app.include_router() for all +five routers. +""" +from __future__ import annotations + + +def register_startup(app): + """Attach the router-wiring startup event to a FastAPI app instance.""" + + @app.on_event("startup") + async def _wire_routers(): + import routes._wire # noqa — side-effect: registers shared + mounts routers