Skip to content

Commit 03ba365

Browse files
committed
Merge branch 'next' of https://github.com/Geode-solutions/OpenGeodeWeb-Back into feat/database
2 parents e3ac529 + 07a969d commit 03ba365

File tree

5 files changed

+53
-40
lines changed

5 files changed

+53
-40
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ __pycache__
1010
uploads
1111
node_modules
1212
schemas.json
13+
.mypy_cache
1314
*.db

.vscode/settings.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,11 @@
33
"."
44
],
55
"python.testing.unittestEnabled": false,
6-
"python.testing.pytestEnabled": true
6+
"python.testing.pytestEnabled": true,
7+
"mypy-type-checker.args": [
8+
"--config-file=mypy.ini"
9+
],
10+
"mypy-type-checker.interpreter": [
11+
"${workspaceFolder}/venv/bin/python"
12+
]
713
}

src/opengeodeweb_back/geode_functions.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
import os
33

44
# Third party imports
5-
import opengeode_geosciences as og_gs
6-
import opengeode as og
5+
import opengeode_geosciences as og_gs # type: ignore
6+
import opengeode as og # type: ignore
77
import werkzeug
88
import flask
99

src/opengeodeweb_back/geode_objects.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
# Standard library imports
22

33
# Third party imports
4-
import opengeode as og
5-
import opengeode_io as og_io
6-
import opengeode_inspector as og_inspector
7-
import opengeode_geosciences as og_gs
8-
import opengeode_geosciencesio as og_gs_io
9-
import geode_viewables as g_v
4+
import opengeode as og # type: ignore
5+
import opengeode_io as og_io # type: ignore
6+
import opengeode_inspector as og_inspector # type: ignore
7+
import opengeode_geosciences as og_gs # type: ignore
8+
import opengeode_geosciencesio as og_gs_io # type: ignore
9+
import geode_viewables as g_v # type: ignore
1010

1111
# Local application imports
1212

src/opengeodeweb_back/utils_functions.py

Lines changed: 37 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@
33
import threading
44
import time
55
import zipfile
6+
from collections.abc import Callable
67
from typing import Any
78

89
# Third party imports
910
import flask
10-
import fastjsonschema
11+
import fastjsonschema # type: ignore
1112
import importlib.metadata as metadata
1213
import shutil
14+
from werkzeug.exceptions import HTTPException
1315
import werkzeug
1416

1517
# Local application imports
@@ -18,40 +20,40 @@
1820
from .database import database
1921

2022

21-
def increment_request_counter(current_app):
23+
def increment_request_counter(current_app: flask.Flask) -> None:
2224
if "REQUEST_COUNTER" in current_app.config:
23-
REQUEST_COUNTER = int(current_app.config.get("REQUEST_COUNTER"))
25+
REQUEST_COUNTER = int(current_app.config.get("REQUEST_COUNTER", 0))
2426
REQUEST_COUNTER += 1
2527
current_app.config.update(REQUEST_COUNTER=REQUEST_COUNTER)
2628

2729

28-
def decrement_request_counter(current_app):
30+
def decrement_request_counter(current_app: flask.Flask) -> None:
2931
if "REQUEST_COUNTER" in current_app.config:
30-
REQUEST_COUNTER = int(current_app.config.get("REQUEST_COUNTER"))
32+
REQUEST_COUNTER = int(current_app.config.get("REQUEST_COUNTER", 0))
3133
REQUEST_COUNTER -= 1
3234
current_app.config.update(REQUEST_COUNTER=REQUEST_COUNTER)
3335

3436

35-
def update_last_request_time(current_app):
37+
def update_last_request_time(current_app: flask.Flask) -> None:
3638
if "LAST_REQUEST_TIME" in current_app.config:
3739
LAST_REQUEST_TIME = time.time()
3840
current_app.config.update(LAST_REQUEST_TIME=LAST_REQUEST_TIME)
3941

4042

41-
def before_request(current_app):
43+
def before_request(current_app: flask.Flask) -> None:
4244
increment_request_counter(current_app)
4345

4446

45-
def teardown_request(current_app):
47+
def teardown_request(current_app: flask.Flask) -> None:
4648
decrement_request_counter(current_app)
4749
update_last_request_time(current_app)
4850

4951

50-
def kill_task(current_app):
51-
REQUEST_COUNTER = int(current_app.config.get("REQUEST_COUNTER"))
52-
LAST_PING_TIME = float(current_app.config.get("LAST_PING_TIME"))
53-
LAST_REQUEST_TIME = float(current_app.config.get("LAST_REQUEST_TIME"))
54-
MINUTES_BEFORE_TIMEOUT = float(current_app.config.get("MINUTES_BEFORE_TIMEOUT"))
52+
def kill_task(current_app: flask.Flask) -> None:
53+
REQUEST_COUNTER = int(current_app.config.get("REQUEST_COUNTER", 0))
54+
LAST_PING_TIME = float(current_app.config.get("LAST_PING_TIME", 0))
55+
LAST_REQUEST_TIME = float(current_app.config.get("LAST_REQUEST_TIME", 0))
56+
MINUTES_BEFORE_TIMEOUT = float(current_app.config.get("MINUTES_BEFORE_TIMEOUT", 0))
5557
current_time = time.time()
5658
minutes_since_last_request = (current_time - LAST_REQUEST_TIME) / 60
5759
minutes_since_last_ping = (current_time - LAST_PING_TIME) / 60
@@ -66,12 +68,12 @@ def kill_task(current_app):
6668
kill_server()
6769

6870

69-
def kill_server():
71+
def kill_server() -> None:
7072
print("Server timed out due to inactivity, shutting down...", flush=True)
7173
os._exit(0)
7274

7375

74-
def versions(list_packages: list):
76+
def versions(list_packages: list[str]) -> list[dict[str, str]]:
7577
list_with_versions = []
7678
for package in list_packages:
7779
list_with_versions.append(
@@ -80,7 +82,7 @@ def versions(list_packages: list):
8082
return list_with_versions
8183

8284

83-
def validate_request(request, schema):
85+
def validate_request(request: flask.Request, schema: dict[str, str]) -> None:
8486
json_data = request.get_json(force=True, silent=True)
8587

8688
if json_data is None:
@@ -94,22 +96,26 @@ def validate_request(request, schema):
9496
flask.abort(400, error_msg)
9597

9698

97-
def set_interval(func, sec, args=None):
98-
def func_wrapper():
99-
set_interval(func, sec, args)
100-
func(args)
99+
def set_interval(
100+
function: Callable[[Any], None], seconds: float, args: Any
101+
) -> threading.Timer:
102+
def function_wrapper() -> None:
103+
set_interval(function, seconds, args)
104+
function(args)
101105

102-
t = threading.Timer(sec, func_wrapper)
103-
t.daemon = True
104-
t.start()
105-
return t
106+
timer = threading.Timer(seconds, function_wrapper)
107+
timer.daemon = True
108+
timer.start()
109+
return timer
106110

107111

108-
def extension_from_filename(filename):
112+
def extension_from_filename(filename: str) -> str:
109113
return os.path.splitext(filename)[1][1:]
110114

111115

112-
def send_file(upload_folder, saved_files, new_file_name):
116+
def send_file(
117+
upload_folder: str, saved_files: str, new_file_name: str
118+
) -> flask.Response:
113119
if len(saved_files) == 1:
114120
mimetype = "application/octet-binary"
115121
else:
@@ -134,13 +140,13 @@ def send_file(upload_folder, saved_files, new_file_name):
134140
return response
135141

136142

137-
def handle_exception(e):
138-
response = e.get_response()
143+
def handle_exception(exception: HTTPException) -> flask.Response:
144+
response = exception.get_response()
139145
response.data = flask.json.dumps(
140146
{
141-
"code": e.code,
142-
"name": e.name,
143-
"description": e.description,
147+
"code": exception.code,
148+
"name": exception.name,
149+
"description": exception.description,
144150
}
145151
)
146152
response.content_type = "application/json"

0 commit comments

Comments
 (0)