Basic registry, with survey stores
Move to standard src/ dir
versions: sqlmodel official, pydantic v2
etc...
This commit is contained in:
phil 2023-12-13 01:25:00 +05:30
parent 5494f6085f
commit 049b8c9927
31 changed files with 670 additions and 526 deletions

40
src/gisaf/application.py Normal file
View file

@ -0,0 +1,40 @@
from contextlib import asynccontextmanager
import logging
from typing import Any
#import colorama
#colorama.init()
from fastapi import FastAPI, responses
from .api import api
from .config import conf
from .registry import registry, ModelRegistry
logging.basicConfig(level=conf.gisaf.debugLevel)
logger = logging.getLogger(__name__)
## Subclass FastAPI to add attributes to be used globally, ie. registry
class GisafExtra:
registry: ModelRegistry
#raw_survey_models: dict[str, Any] = {}
#survey_models: dict[str, Any] = {}
class GisafFastAPI(FastAPI):
gisaf_extra: GisafExtra
@asynccontextmanager
async def lifespan(app: FastAPI):
await registry.make_registry(app)
yield
app = FastAPI(
debug=False,
title=conf.gisaf.title,
version=conf.version,
lifespan=lifespan,
default_response_class=responses.ORJSONResponse,
)
app.mount('/v2', api)