Skip to content

Commit e97b4e5

Browse files
authored
♻️Maintenance: mypy simcore sdk (#6118)
1 parent 2d36783 commit e97b4e5

File tree

21 files changed

+83
-46
lines changed

21 files changed

+83
-46
lines changed

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1683,7 +1683,6 @@ jobs:
16831683
run: ./ci/github/unit-testing/simcore-sdk.bash install
16841684
- name: typecheck
16851685
run: ./ci/github/unit-testing/simcore-sdk.bash typecheck
1686-
continue-on-error: true
16871686
- name: test
16881687
if: always()
16891688
run: ./ci/github/unit-testing/simcore-sdk.bash test

packages/models-library/src/models_library/api_schemas_storage.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ class Config:
7070
}
7171

7272

73-
FileLocationArray = ListModel[FileLocation]
73+
FileLocationArray: TypeAlias = ListModel[FileLocation]
7474

7575

7676
# /locations/{location_id}/datasets

packages/service-library/src/servicelib/common_aiopg_utils.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
This module was necessary because simcore-sdk (an aiohttp-independent package) still needs some
44
of the helpers here.
55
"""
6+
67
import logging
78
from dataclasses import asdict, dataclass
89

packages/simcore-sdk/requirements/_test.in

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,7 @@ pytest-sugar
2929
pytest-xdist
3030
python-dotenv
3131
requests
32-
types-aiobotocore[s3] # s3 storage
32+
sqlalchemy[mypy]
33+
types-aiobotocore[s3]
34+
types-aiofiles
35+
types-tqdm

packages/simcore-sdk/requirements/_test.txt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,10 @@ multidict==6.0.5
176176
# -c requirements/_base.txt
177177
# aiohttp
178178
# yarl
179+
mypy==1.11.0
180+
# via sqlalchemy
181+
mypy-extensions==1.0.0
182+
# via mypy
179183
networkx==3.3
180184
# via cfn-lint
181185
openapi-schema-validator==0.6.2
@@ -288,28 +292,38 @@ sqlalchemy==1.4.52
288292
# via
289293
# -c requirements/../../../requirements/constraints.txt
290294
# -c requirements/_base.txt
295+
# -r requirements/_test.in
291296
# alembic
297+
sqlalchemy2-stubs==0.0.2a38
298+
# via sqlalchemy
292299
sympy==1.13.0
293300
# via cfn-lint
294301
termcolor==2.4.0
295302
# via pytest-sugar
296303
tomli==2.0.1
297304
# via
298305
# coverage
306+
# mypy
299307
# pytest
300308
types-aiobotocore==2.13.1
301309
# via -r requirements/_test.in
302310
types-aiobotocore-s3==2.13.1
303311
# via types-aiobotocore
312+
types-aiofiles==24.1.0.20240626
313+
# via -r requirements/_test.in
304314
types-awscrt==0.21.2
305315
# via botocore-stubs
316+
types-tqdm==4.66.0.20240417
317+
# via -r requirements/_test.in
306318
typing-extensions==4.12.2
307319
# via
308320
# -c requirements/_base.txt
309321
# alembic
310322
# aws-sam-translator
311323
# cfn-lint
324+
# mypy
312325
# pydantic
326+
# sqlalchemy2-stubs
313327
# types-aiobotocore
314328
# types-aiobotocore-s3
315329
urllib3==2.2.2

packages/simcore-sdk/requirements/_tools.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,12 @@ isort==5.13.2
2929
mccabe==0.7.0
3030
# via pylint
3131
mypy==1.11.0
32-
# via -r requirements/../../../requirements/devenv.txt
32+
# via
33+
# -c requirements/_test.txt
34+
# -r requirements/../../../requirements/devenv.txt
3335
mypy-extensions==1.0.0
3436
# via
37+
# -c requirements/_test.txt
3538
# black
3639
# mypy
3740
nodeenv==1.9.1

packages/simcore-sdk/setup.cfg

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,8 @@ markers =
2020
acceptance_test: "marks tests as 'acceptance tests' i.e. does the system do what the user expects? Typically those are workflows."
2121
testit: "marks test to run during development"
2222
heavy_load: "mark tests that require large amount of data"
23+
24+
[mypy]
25+
plugins =
26+
pydantic.mypy
27+
sqlalchemy.ext.mypy.plugin

packages/simcore-sdk/src/simcore_sdk/node_data/data_manager.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from pathlib import Path
33
from tempfile import TemporaryDirectory
44

5+
from models_library.basic_types import IDStr
56
from models_library.projects import ProjectID
67
from models_library.projects_nodes_io import NodeID, StorageFileID
78
from models_library.users import UserID
@@ -23,7 +24,7 @@ def __create_s3_object_key(
2324
project_id: ProjectID, node_uuid: NodeID, file_path: Path | str
2425
) -> StorageFileID:
2526
file_name = file_path.name if isinstance(file_path, Path) else file_path
26-
return parse_obj_as(StorageFileID, f"{project_id}/{node_uuid}/{file_name}")
27+
return parse_obj_as(StorageFileID, f"{project_id}/{node_uuid}/{file_name}") # type: ignore[arg-type]
2728

2829

2930
def __get_s3_name(path: Path, *, is_archive: bool) -> str:
@@ -97,7 +98,7 @@ async def _pull_legacy_archive(
9798
) -> None:
9899
# NOTE: the legacy way of storing states was as zip archives
99100
async with progress_bar.sub_progress(
100-
steps=2, description=f"pulling {destination_path.name}"
101+
steps=2, description=IDStr(f"pulling {destination_path.name}")
101102
) as sub_prog:
102103
with TemporaryDirectory() as tmp_dir_name:
103104
archive_file = Path(tmp_dir_name) / __get_s3_name(

packages/simcore-sdk/src/simcore_sdk/node_ports_common/_filemanager.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import logging
2+
from typing import cast
23

34
from aiohttp import ClientError, ClientSession
45
from models_library.api_schemas_storage import (
@@ -7,11 +8,10 @@
78
FileUploadCompleteResponse,
89
FileUploadCompleteState,
910
FileUploadCompletionBody,
10-
LocationID,
11-
LocationName,
1211
UploadedPart,
1312
)
1413
from models_library.generics import Envelope
14+
from models_library.projects_nodes_io import LocationID, LocationName
1515
from models_library.users import UserID
1616
from models_library.utils.fastapi_encoders import jsonable_encoder
1717
from pydantic import AnyUrl, parse_obj_as
@@ -37,7 +37,7 @@ async def _get_location_id_from_location_name(
3737
resp = await storage_client.get_storage_locations(session=session, user_id=user_id)
3838
for location in resp:
3939
if location.name == store:
40-
return location.id
40+
return cast(LocationID, location.id) # mypy wants it
4141
# location id not found
4242
raise exceptions.S3InvalidStore(store)
4343

packages/simcore-sdk/src/simcore_sdk/node_ports_common/constants.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from typing import Final
22

3-
from models_library.api_schemas_storage import LocationID
3+
from models_library.projects_nodes_io import LocationID
44

55
CHUNK_SIZE: Final[int] = 16 * 1024 * 1024
66
MINUTE: Final[int] = 60

0 commit comments

Comments
 (0)