Skip to content

Commit 638fdcb

Browse files
committed
type app.py
1 parent c0e82c4 commit 638fdcb

File tree

1 file changed

+19
-14
lines changed

1 file changed

+19
-14
lines changed

src/opengeodeweb_back/app.py

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
import argparse
44
import os
55
import time
6+
from typing import Any
67

78
import flask
8-
import flask_cors
9+
import flask_cors # type: ignore
10+
from flask import Flask, Response
911
from flask_cors import cross_origin
1012
from werkzeug.exceptions import HTTPException
1113

@@ -16,7 +18,7 @@
1618

1719

1820
""" Global config """
19-
app = flask.Flask(__name__)
21+
app: Flask = flask.Flask(__name__)
2022

2123
""" Config variables """
2224
FLASK_DEBUG = True if os.environ.get("FLASK_DEBUG", default=None) == "True" else False
@@ -26,13 +28,15 @@
2628
else:
2729
app.config.from_object(app_config.DevConfig)
2830

29-
DEFAULT_HOST = app.config.get("DEFAULT_HOST")
30-
DEFAULT_PORT = int(app.config.get("DEFAULT_PORT"))
31-
DEFAULT_DATA_FOLDER_PATH = app.config.get("DEFAULT_DATA_FOLDER_PATH")
32-
ORIGINS = app.config.get("ORIGINS")
33-
TIMEOUT = int(app.config.get("MINUTES_BEFORE_TIMEOUT"))
34-
SSL = app.config.get("SSL")
35-
SECONDS_BETWEEN_SHUTDOWNS = float(app.config.get("SECONDS_BETWEEN_SHUTDOWNS"))
31+
DEFAULT_HOST: str = app.config.get("DEFAULT_HOST") or "localhost"
32+
DEFAULT_PORT: int = int(app.config.get("DEFAULT_PORT") or 5000)
33+
DEFAULT_DATA_FOLDER_PATH: str = app.config.get("DEFAULT_DATA_FOLDER_PATH") or "./data"
34+
ORIGINS: Any = app.config.get("ORIGINS")
35+
TIMEOUT: int = int(app.config.get("MINUTES_BEFORE_TIMEOUT") or 30)
36+
SSL: Any = app.config.get("SSL")
37+
SECONDS_BETWEEN_SHUTDOWNS: float = float(
38+
app.config.get("SECONDS_BETWEEN_SHUTDOWNS") or 60.0
39+
)
3640

3741

3842
app.register_blueprint(
@@ -54,21 +58,21 @@
5458

5559

5660
@app.errorhandler(HTTPException)
57-
def errorhandler(e):
61+
def errorhandler(e: HTTPException) -> tuple[dict[str, Any], int] | Response:
5862
return utils_functions.handle_exception(e)
5963

6064

6165
@app.route(
6266
"/error",
6367
methods=["POST"],
6468
)
65-
def return_error():
69+
def return_error() -> None:
6670
flask.abort(500, f"Test")
6771

6872

6973
@app.route("/", methods=["POST"])
7074
@cross_origin()
71-
def root():
75+
def root() -> Response:
7276
return flask.make_response({}, 200)
7377

7478

@@ -79,7 +83,7 @@ def kill() -> None:
7983
os._exit(0)
8084

8185

82-
def run_server():
86+
def run_server() -> None:
8387
parser = argparse.ArgumentParser(
8488
prog="OpenGeodeWeb-Back", description="Backend server for OpenGeodeWeb"
8589
)
@@ -135,7 +139,8 @@ def run_server():
135139
flush=True,
136140
)
137141

138-
db_path = os.path.join(args.data_folder_path, app.config.get("DATABASE_FILENAME"))
142+
db_filename: str = app.config.get("DATABASE_FILENAME") or "database.db"
143+
db_path = os.path.join(args.data_folder_path, db_filename)
139144
os.makedirs(os.path.dirname(db_path), exist_ok=True)
140145
init_database(db_path)
141146
print(f"Database initialized at: {db_path}", flush=True)

0 commit comments

Comments
 (0)