From 47673b68db7498e2b419d911c6cba1f040de38d0 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sun, 3 Mar 2024 23:34:26 +0000 Subject: [PATCH] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- backend/app/database.py | 13 +++++++++++-- backend/app/main.py | 5 +++++ backend/app/settings.py | 1 + 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/backend/app/database.py b/backend/app/database.py index 3e87ea9..a7e064a 100644 --- a/backend/app/database.py +++ b/backend/app/database.py @@ -1,7 +1,12 @@ import os from collections.abc import AsyncGenerator -from sqlalchemy.ext.asyncio import AsyncSession, async_sessionmaker, create_async_engine, AsyncEngine +from sqlalchemy.ext.asyncio import ( + AsyncSession, + async_sessionmaker, + create_async_engine, + AsyncEngine, +) from app.auth.models import Role # noqa: F401 from app.file_transfer.models import File, Webhook # noqa: F401 @@ -10,6 +15,7 @@ engine: AsyncEngine | None = None SQLALCHEMY_DATABASE_URL = os.getenv("DATABASE_URL") + def get_engine() -> AsyncEngine: global engine @@ -22,6 +28,8 @@ def get_engine() -> AsyncEngine: async_session_maker: None | async_sessionmaker = None + + def get_session_maker(): global async_session_maker if async_session_maker is None: @@ -30,6 +38,7 @@ def get_session_maker(): ) return async_session_maker + async def initialize_database() -> None: async with get_engine().begin() as conn: await conn.run_sync(Base.metadata.drop_all) @@ -37,5 +46,5 @@ async def initialize_database() -> None: async def get_async_session() -> AsyncGenerator[AsyncSession, None]: - async with get_session_maker() as session: # type: ignore + async with get_session_maker() as session: # type: ignore yield session diff --git a/backend/app/main.py b/backend/app/main.py index 69473c1..a05cbd7 100644 --- a/backend/app/main.py +++ b/backend/app/main.py @@ -14,6 +14,7 @@ from app.settings import APISettings + @asynccontextmanager async def lifespan(_: FastAPI) -> AsyncGenerator[None, None]: print("Application is starting up") @@ -41,15 +42,19 @@ def make_app() -> FastAPI: app = FastAPI(lifespan=lifespan) app.include_router(auth_router, prefix="/auth") app.include_router(file_router, prefix="/files") + @app.get("/") async def root() -> str: return "Hello World" + return app + def run() -> None: app = make_app() settings = APISettings() uvicorn.run(app, host=settings.host, port=settings.port, log_level="info") + if __name__ == "__main__": run() diff --git a/backend/app/settings.py b/backend/app/settings.py index 09596a4..9abd76c 100644 --- a/backend/app/settings.py +++ b/backend/app/settings.py @@ -1,5 +1,6 @@ from pydantic_settings import BaseSettings, SettingsConfigDict + class APISettings(BaseSettings): host: str = "0.0.0.0" port: int = 8002