Skip to content

Commit cb607cd

Browse files
authored
♻️ webserver: fixes last mypy issues and activating in CI's job (#4519)
1 parent 59d8474 commit cb607cd

File tree

14 files changed

+40
-87
lines changed

14 files changed

+40
-87
lines changed

.github/workflows/ci-testing-deploy.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,10 @@ jobs:
292292
run: ./ci/helpers/show_system_versions.bash
293293
- name: install webserver
294294
run: ./ci/github/unit-testing/webserver.bash install
295+
- name: typecheck
296+
run: ./ci/github/unit-testing/webserver.bash typecheck
295297
- name: test isolated
298+
if: always()
296299
run: ./ci/github/unit-testing/webserver.bash test_isolated
297300
- name: test
298301
run: ./ci/github/unit-testing/webserver.bash test_with_db 01

services/web/server/src/simcore_service_webserver/announcements/_models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def check_start_before_end(cls, v, values):
2929
return v
3030

3131
def expired(self) -> bool:
32-
return self.end <= arrow.utcnow().datetime
32+
return self.end <= arrow.utcnow().datetime # type: ignore[no-any-return]
3333

3434
class Config:
3535
schema_extra: ClassVar[dict[str, Any]] = {

services/web/server/src/simcore_service_webserver/catalog/plugin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
def setup_catalog(app: web.Application):
2424
# ensures routes are names that corresponds to function names
2525
for route_def in _handlers.routes:
26-
route_def.kwargs["name"] = route_def.handler.__name__ # type: ignore
26+
route_def.kwargs["name"] = route_def.handler.__name__
2727

2828
app.add_routes(_handlers.routes)
2929

services/web/server/src/simcore_service_webserver/login/_registration.py

Lines changed: 5 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,14 @@
55
"""
66

77
import logging
8+
from collections.abc import Iterator
89
from contextlib import contextmanager
910
from datetime import datetime
10-
from typing import Iterator, Literal
1111

1212
from aiohttp import web
1313
from models_library.basic_types import IdInt
1414
from models_library.emails import LowerCaseEmailStr
15-
from pydantic import (
16-
BaseModel,
17-
Field,
18-
Json,
19-
PositiveInt,
20-
ValidationError,
21-
parse_raw_as,
22-
validator,
23-
)
15+
from pydantic import BaseModel, Field, Json, PositiveInt, ValidationError, validator
2416
from servicelib.mimetype_constants import MIMETYPE_APPLICATION_JSON
2517
from simcore_postgres_database.models.confirmations import ConfirmationAction
2618
from yarl import URL
@@ -31,11 +23,7 @@
3123
is_service_invitation_code,
3224
validate_invitation_url,
3325
)
34-
from ._confirmation import (
35-
get_expiration_date,
36-
is_confirmation_expired,
37-
validate_confirmation_code,
38-
)
26+
from ._confirmation import is_confirmation_expired, validate_confirmation_code
3927
from ._constants import MSG_EMAIL_EXISTS, MSG_INVITATIONS_CONTACT_SUFFIX
4028
from .settings import LoginOptions
4129
from .storage import AsyncpgStorage, BaseConfirmationTokenDict, ConfirmationTokenDict
@@ -65,7 +53,7 @@ class InvitationData(BaseModel):
6553

6654

6755
class _InvitationValidator(BaseModel):
68-
action: Literal[ConfirmationAction.INVITATION]
56+
action: ConfirmationAction
6957
data: Json[InvitationData] # pylint: disable=unsubscriptable-object
7058

7159
@validator("action", pre=True)
@@ -87,7 +75,6 @@ async def check_other_registrations(
8775
db: AsyncpgStorage,
8876
cfg: LoginOptions,
8977
) -> None:
90-
9178
if user := await db.get_user({"email": email}):
9279
# An account already registered with this email
9380
#
@@ -150,12 +137,11 @@ async def create_invitation_token(
150137
"trial_account_days": trial_days,
151138
}
152139
)
153-
confirmation = await db.create_confirmation(
140+
return await db.create_confirmation(
154141
user_id=user_id,
155142
action=ConfirmationAction.INVITATION.name,
156143
data=data_model.json(),
157144
)
158-
return confirmation
159145

160146

161147
@contextmanager
@@ -283,25 +269,3 @@ def get_invitation_url(
283269
# https://some-web-url.io/#/registration/?invitation={code}
284270
# NOTE: Uniform encoding in front-end fragments https://github.com/ITISFoundation/osparc-simcore/issues/1975
285271
return origin.with_fragment(f"/registration/?invitation={code}")
286-
287-
288-
def get_confirmation_info(
289-
cfg: LoginOptions, confirmation: ConfirmationTokenDict
290-
) -> ConfirmationTokenInfoDict:
291-
"""
292-
Extends ConfirmationTokenDict by adding extra info and
293-
deserializing action's data entry
294-
"""
295-
info: ConfirmationTokenInfoDict = ConfirmationTokenInfoDict(**confirmation)
296-
297-
action = ConfirmationAction(confirmation["action"])
298-
if (data_type := ACTION_TO_DATA_TYPE[action]) and (data := confirmation["data"]):
299-
info["data"] = parse_raw_as(data_type, data)
300-
301-
# extra
302-
info["expires"] = get_expiration_date(cfg, confirmation)
303-
304-
if confirmation["action"] == ConfirmationAction.INVITATION.name:
305-
info["url"] = f"{get_invitation_url(confirmation)}"
306-
307-
return info

services/web/server/src/simcore_service_webserver/projects/_comments_handlers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
from ..security.decorators import permission_required
3131
from ..utils_aiohttp import envelope_json_response
3232
from . import _comments_api, projects_api
33-
from ._handlers_crud import RequestContext
33+
from ._common_models import RequestContext
3434
from .exceptions import ProjectNotFoundError
3535

3636
_logger = logging.getLogger(__name__)
@@ -42,7 +42,7 @@ async def wrapper(request: web.Request) -> web.StreamResponse:
4242
try:
4343
return await handler(request)
4444

45-
except (ProjectNotFoundError) as exc:
45+
except ProjectNotFoundError as exc:
4646
raise web.HTTPNotFound(reason=f"{exc}") from exc
4747

4848
return wrapper

services/web/server/src/simcore_service_webserver/projects/_handlers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
from ..security.decorators import permission_required
3434
from ..users import api
3535
from . import projects_api
36-
from ._handlers_crud import ProjectPathParams, RequestContext
36+
from ._common_models import ProjectPathParams, RequestContext
3737
from .exceptions import (
3838
ProjectInvalidRightsError,
3939
ProjectNotFoundError,

services/web/server/src/simcore_service_webserver/projects/_nodes_api.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ async def fake_screenshots_factory(
123123
file_url = await get_download_link(request.app, user_id, filelink)
124124
screenshots.append(
125125
NodeScreenshot(
126-
thumbnail_url=f"https://placehold.co/170x120?text={text}",
126+
thumbnail_url=f"https://placehold.co/170x120?text={text}", # type: ignore[arg-type]
127127
file_url=file_url,
128128
)
129129
)
@@ -148,16 +148,16 @@ async def fake_screenshots_factory(
148148
screenshots = [
149149
*(
150150
NodeScreenshot(
151-
thumbnail_url=f"https://picsum.photos/seed/{node_id.int + n}/170/120",
152-
file_url=f"https://picsum.photos/seed/{node_id.int + n}/500",
151+
thumbnail_url=f"https://picsum.photos/seed/{node_id.int + n}/170/120", # type: ignore[arg-type]
152+
file_url=f"https://picsum.photos/seed/{node_id.int + n}/500", # type: ignore[arg-type]
153153
mimetype="image/jpeg",
154154
)
155155
for n in range(count)
156156
),
157157
*(
158158
NodeScreenshot(
159-
thumbnail_url=f"https://placehold.co/170x120?text={text}",
160-
file_url=f"https://placehold.co/500x500?text={text}",
159+
thumbnail_url=f"https://placehold.co/170x120?text={text}", # type: ignore[arg-type]
160+
file_url=f"https://placehold.co/500x500?text={text}", # type: ignore[arg-type]
161161
mimetype="image/svg+xml",
162162
)
163163
for n in range(count)

services/web/server/src/simcore_service_webserver/projects/_nodes_handlers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
from simcore_postgres_database.models.users import UserRole
3939

4040
from .._constants import APP_SETTINGS_KEY, MSG_UNDER_DEVELOPMENT
41-
from .._meta import api_version_prefix as VTAG
41+
from .._meta import API_VTAG as VTAG
4242
from ..catalog import client as catalog_client
4343
from ..director_v2 import api
4444
from ..director_v2.exceptions import DirectorServiceError
@@ -47,7 +47,7 @@
4747
from ..users.api import get_user_role
4848
from ..utils_aiohttp import envelope_json_response
4949
from . import projects_api
50-
from ._handlers_crud import ProjectPathParams, RequestContext
50+
from ._common_models import ProjectPathParams, RequestContext
5151
from ._nodes_api import NodeScreenshot, fake_screenshots_factory
5252
from .db import ProjectDBAPI
5353
from .exceptions import (

services/web/server/src/simcore_service_webserver/projects/_permalink_api.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import asyncio
22
import logging
3-
from typing import Any, Callable, Coroutine, cast
3+
from collections.abc import Callable, Coroutine
4+
from typing import Any, cast
45

56
from aiohttp import web
67
from models_library.api_schemas_webserver.permalinks import ProjectPermalink
@@ -19,20 +20,17 @@
1920

2021
def register_factory(app: web.Application, factory_coro: _CreateLinkCallable):
2122
if _create := app.get(_PROJECT_PERMALINK):
22-
raise PermalinkFactoryError(
23-
f"Permalink factory can only be set once: registered {_create}"
24-
)
23+
msg = f"Permalink factory can only be set once: registered {_create}"
24+
raise PermalinkFactoryError(msg)
2525
app[_PROJECT_PERMALINK] = factory_coro
2626

2727

2828
def _get_factory(app: web.Application) -> _CreateLinkCallable:
29-
3029
if _create := app.get(_PROJECT_PERMALINK):
3130
return cast(_CreateLinkCallable, _create)
3231

33-
raise PermalinkFactoryError(
34-
"Undefined permalink factory. Check plugin initialization."
35-
)
32+
msg = "Undefined permalink factory. Check plugin initialization."
33+
raise PermalinkFactoryError(msg)
3634

3735

3836
_PERMALINK_CREATE_TIMEOUT_S = 2
@@ -41,7 +39,6 @@ def _get_factory(app: web.Application) -> _CreateLinkCallable:
4139
async def _create_permalink(
4240
request: web.Request, project_id: ProjectID
4341
) -> ProjectPermalink:
44-
4542
create = _get_factory(request.app)
4643
assert create # nosec
4744

@@ -51,9 +48,8 @@ async def _create_permalink(
5148
)
5249
return permalink
5350
except asyncio.TimeoutError as err:
54-
raise PermalinkFactoryError(
55-
f"Permalink factory callback '{create}' timed out after {_PERMALINK_CREATE_TIMEOUT_S} secs"
56-
) from err
51+
msg = f"Permalink factory callback '{create}' timed out after {_PERMALINK_CREATE_TIMEOUT_S} secs"
52+
raise PermalinkFactoryError(msg) from err
5753

5854

5955
async def update_or_pop_permalink_in_project(
@@ -77,3 +73,6 @@ async def update_or_pop_permalink_in_project(
7773
project.pop("permalink", None)
7874

7975
return None
76+
77+
78+
__all__: tuple[str, ...] = ("ProjectPermalink",)

services/web/server/src/simcore_service_webserver/projects/_ports_handlers.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
from ..login.decorators import login_required
2525
from ..security.decorators import permission_required
2626
from . import _ports_api, projects_api
27-
from ._handlers_crud import ProjectPathParams, RequestContext
27+
from ._common_models import ProjectPathParams, RequestContext
2828
from .db import ProjectDBAPI
2929
from .exceptions import (
3030
NodeNotFoundError,
@@ -70,7 +70,6 @@ async def wrapper(request: web.Request) -> web.Response:
7070
async def _get_validated_workbench_model(
7171
app: web.Application, project_id: ProjectID, user_id: UserID
7272
) -> dict[NodeID, Node]:
73-
7473
project: ProjectDict = await projects_api.get_project_for_user(
7574
app,
7675
project_uuid=f"{project_id}",

0 commit comments

Comments
 (0)