From fbf6c550d2cfab07b744953ab2c9bf02a9f460ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn-Michael=20Miehe?= <40151420+ldericher@users.noreply.github.com> Date: Sat, 17 Sep 2022 19:13:59 +0000 Subject: [PATCH] move main function, launch module directly --- api/.vscode/launch.json | 2 +- api/ovdashboard_api/__init__.py | 3 +++ api/ovdashboard_api/__main__.py | 21 +++++++++++++++++++++ api/ovdashboard_api/{main.py => app.py} | 20 -------------------- 4 files changed, 25 insertions(+), 21 deletions(-) create mode 100644 api/ovdashboard_api/__main__.py rename api/ovdashboard_api/{main.py => app.py} (75%) diff --git a/api/.vscode/launch.json b/api/.vscode/launch.json index 8a57e6e..ff096b8 100644 --- a/api/.vscode/launch.json +++ b/api/.vscode/launch.json @@ -8,7 +8,7 @@ "name": "Main Module", "type": "python", "request": "launch", - "module": "ovdashboard_api.main", + "module": "ovdashboard_api", "justMyCode": true } ] diff --git a/api/ovdashboard_api/__init__.py b/api/ovdashboard_api/__init__.py index 038ce7a..fcdec95 100644 --- a/api/ovdashboard_api/__init__.py +++ b/api/ovdashboard_api/__init__.py @@ -9,8 +9,11 @@ from logging.config import dictConfig from pydantic import BaseModel +from .app import app from .settings import SETTINGS +__all__ = ["app"] + class LogConfig(BaseModel): """ diff --git a/api/ovdashboard_api/__main__.py b/api/ovdashboard_api/__main__.py new file mode 100644 index 0000000..e983129 --- /dev/null +++ b/api/ovdashboard_api/__main__.py @@ -0,0 +1,21 @@ +from uvicorn import run as uvicorn_run + +from .dav_common import webdav_check + + +def main() -> None: + """ + If the `main` script is run, `uvicorn` is used to run the app. + """ + + if webdav_check(): + uvicorn_run( + app="ovdashboard_api:app", + host="0.0.0.0", + port=8000, + reload=True, + ) + + +if __name__ == "__main__": + main() diff --git a/api/ovdashboard_api/main.py b/api/ovdashboard_api/app.py similarity index 75% rename from api/ovdashboard_api/main.py rename to api/ovdashboard_api/app.py index bdb201b..41c7a11 100644 --- a/api/ovdashboard_api/main.py +++ b/api/ovdashboard_api/app.py @@ -9,9 +9,7 @@ Creates the main `FastAPI` app. from fastapi import FastAPI from fastapi.middleware.cors import CORSMiddleware from fastapi.staticfiles import StaticFiles -from uvicorn import run as uvicorn_run -from .dav_common import webdav_check from .routers import main_router from .settings import SETTINGS @@ -56,21 +54,3 @@ else: allow_headers=["*"], expose_headers=["*"], ) - - -def main() -> None: - """ - If the `main` script is run, `uvicorn` is used to run the app. - """ - - if webdav_check(): - uvicorn_run( - app="ovdashboard_api.main:app", - host="0.0.0.0", - port=8000, - reload=True, - ) - - -if __name__ == "__main__": - main()