Skip to content

Commit c28d1cc

Browse files
author
Andrei Neagu
committed
removed adapter pattern
1 parent e0a195b commit c28d1cc

File tree

5 files changed

+20
-30
lines changed

5 files changed

+20
-30
lines changed

packages/models-library/src/models_library/api_schemas_directorv2/dynamic_services.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
from typing import Final, TypeAlias
1+
from typing import TypeAlias
22

3-
from pydantic import BaseModel, ByteSize, ConfigDict, Field, TypeAdapter
3+
from pydantic import BaseModel, ByteSize, ConfigDict, Field
44

55
from ..resource_tracker import HardwareInfo, PricingInfo
66
from ..services import ServicePortKey
@@ -75,9 +75,6 @@ class DynamicServiceCreate(ServiceDetails):
7575

7676

7777
DynamicServiceGet: TypeAlias = RunningDynamicServiceDetails
78-
DynamicServiceGetAdapter: Final[TypeAdapter[DynamicServiceGet]] = TypeAdapter(
79-
DynamicServiceGet
80-
)
8178

8279

8380
class GetProjectInactivityResponse(BaseModel):

services/dynamic-scheduler/src/simcore_service_dynamic_scheduler/services/director_v2/_public_client.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@
22
from typing import Any
33

44
from fastapi import FastAPI, status
5-
from models_library.api_schemas_directorv2.dynamic_services import (
6-
DynamicServiceGet,
7-
DynamicServiceGetAdapter,
8-
)
5+
from models_library.api_schemas_directorv2.dynamic_services import DynamicServiceGet
96
from models_library.api_schemas_dynamic_scheduler.dynamic_services import (
107
DynamicServiceStart,
118
)
@@ -15,6 +12,7 @@
1512
NodeGetIdle,
1613
)
1714
from models_library.projects_nodes_io import NodeID
15+
from pydantic import TypeAdapter
1816
from servicelib.fastapi.app_state import SingletonInAppStateMixin
1917
from servicelib.fastapi.http_client import AttachLifespanMixin, HasClientSetupInterface
2018
from servicelib.fastapi.http_client_thin import UnexpectedStatusError
@@ -52,7 +50,7 @@ async def get_status(
5250
if "data" in dict_response:
5351
return NodeGetAdapter.validate_python(dict_response["data"])
5452

55-
return DynamicServiceGetAdapter.validate_python(dict_response)
53+
return TypeAdapter(DynamicServiceGet).validate_python(dict_response)
5654
except UnexpectedStatusError as e:
5755
if (
5856
e.response.status_code # type: ignore[attr-defined] # pylint:disable=no-member
@@ -71,7 +69,7 @@ async def run_dynamic_service(
7169
if "data" in dict_response:
7270
return NodeGetAdapter.validate_python(dict_response["data"])
7371

74-
return DynamicServiceGetAdapter.validate_python(dict_response)
72+
return TypeAdapter(DynamicServiceGet).validate_python(dict_response)
7573

7674
async def stop_dynamic_service(
7775
self,

services/dynamic-scheduler/tests/unit/api_rpc/test_api_rpc__services.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,7 @@
99
from faker import Faker
1010
from fastapi import FastAPI, status
1111
from fastapi.encoders import jsonable_encoder
12-
from models_library.api_schemas_directorv2.dynamic_services import (
13-
DynamicServiceGet,
14-
DynamicServiceGetAdapter,
15-
)
12+
from models_library.api_schemas_directorv2.dynamic_services import DynamicServiceGet
1613
from models_library.api_schemas_dynamic_scheduler.dynamic_services import (
1714
DynamicServiceStart,
1815
DynamicServiceStartAdapter,
@@ -26,6 +23,7 @@
2623
from models_library.projects import ProjectID
2724
from models_library.projects_nodes_io import NodeID
2825
from models_library.users import UserID
26+
from pydantic import TypeAdapter
2927
from pytest_mock import MockerFixture
3028
from pytest_simcore.helpers.typing_env import EnvVarsDict
3129
from servicelib.rabbitmq import RabbitMQRPCClient, RPCServerError
@@ -60,7 +58,7 @@ def node_not_found(faker: Faker) -> NodeID:
6058

6159
@pytest.fixture
6260
def service_status_new_style() -> DynamicServiceGet:
63-
return DynamicServiceGetAdapter.validate_python(
61+
return TypeAdapter(DynamicServiceGet).validate_python(
6462
DynamicServiceGet.model_config["json_schema_extra"]["examples"][1]
6563
)
6664

services/dynamic-scheduler/tests/unit/service_tracker/test__api.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,7 @@
99
import pytest
1010
from faker import Faker
1111
from fastapi import FastAPI
12-
from models_library.api_schemas_directorv2.dynamic_services import (
13-
DynamicServiceGet,
14-
DynamicServiceGetAdapter,
15-
)
12+
from models_library.api_schemas_directorv2.dynamic_services import DynamicServiceGet
1613
from models_library.api_schemas_dynamic_scheduler.dynamic_services import (
1714
DynamicServiceStart,
1815
DynamicServiceStop,
@@ -25,7 +22,7 @@
2522
)
2623
from models_library.projects_nodes_io import NodeID
2724
from models_library.services_enums import ServiceState
28-
from pydantic import NonNegativeInt
25+
from pydantic import NonNegativeInt, TypeAdapter
2926
from pytest_simcore.helpers.typing_env import EnvVarsDict
3027
from servicelib.deferred_tasks import TaskUID
3128
from servicelib.utils import limited_gather
@@ -181,7 +178,10 @@ async def test_set_service_status_task_uid(
181178
_LOW_RATE_POLL_INTERVAL,
182179
),
183180
*[
184-
(DynamicServiceGetAdapter.validate_python(o), NORMAL_RATE_POLL_INTERVAL)
181+
(
182+
TypeAdapter(DynamicServiceGet).validate_python(o),
183+
NORMAL_RATE_POLL_INTERVAL,
184+
)
185185
for o in DynamicServiceGet.model_config["json_schema_extra"]["examples"]
186186
],
187187
(
@@ -211,7 +211,7 @@ def _get_dynamic_service_get_from(
211211
dict_data = DynamicServiceGet.model_config["json_schema_extra"]["examples"][1]
212212
assert "state" in dict_data
213213
dict_data["state"] = service_state
214-
return DynamicServiceGetAdapter.validate_python(dict_data)
214+
return TypeAdapter(DynamicServiceGet).validate_python(dict_data)
215215

216216

217217
def _get_node_get_idle() -> NodeGetIdle:

services/dynamic-scheduler/tests/unit/status_monitor/test_services_status_monitor__monitor.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,7 @@
1515
from fastapi import FastAPI, status
1616
from fastapi.encoders import jsonable_encoder
1717
from httpx import Request, Response
18-
from models_library.api_schemas_directorv2.dynamic_services import (
19-
DynamicServiceGet,
20-
DynamicServiceGetAdapter,
21-
)
18+
from models_library.api_schemas_directorv2.dynamic_services import DynamicServiceGet
2219
from models_library.api_schemas_dynamic_scheduler.dynamic_services import (
2320
DynamicServiceStart,
2421
DynamicServiceStop,
@@ -30,7 +27,7 @@
3027
NodeGetIdleAdapter,
3128
)
3229
from models_library.projects_nodes_io import NodeID
33-
from pydantic import NonNegativeInt
30+
from pydantic import NonNegativeInt, TypeAdapter
3431
from pytest_mock import MockerFixture
3532
from pytest_simcore.helpers.typing_env import EnvVarsDict
3633
from settings_library.rabbit import RabbitSettings
@@ -102,7 +99,7 @@ def _get_dynamic_service_get_legacy_with(
10299
("node_uuid", f"{node_id}"),
103100
],
104101
)
105-
return DynamicServiceGetAdapter.validate_python(dict_data)
102+
return TypeAdapter(DynamicServiceGet).validate_python(dict_data)
106103

107104

108105
def _get_dynamic_service_get_new_style_with(
@@ -119,7 +116,7 @@ def _get_dynamic_service_get_new_style_with(
119116
("node_uuid", f"{node_id}"),
120117
],
121118
)
122-
return DynamicServiceGetAdapter.validate_python(dict_data)
119+
return TypeAdapter(DynamicServiceGet).validate_python(dict_data)
123120

124121

125122
def _get_node_get_idle(node_id: NodeID = _DEFAULT_NODE_ID) -> NodeGetIdle:

0 commit comments

Comments
 (0)