From 8d417c52de76b7815844a4707b3c84ab5a05c005 Mon Sep 17 00:00:00 2001 From: Pedro Crespo <32402063+pcrespov@users.noreply.github.com> Date: Mon, 31 Oct 2022 11:35:13 +0100 Subject: [PATCH] Rename PropertyName by ServicePortKey --- .../models-library/src/models_library/services.py | 8 ++++---- .../models/domains/comp_tasks.py | 8 ++++---- .../models/domains/dynamic_services.py | 6 ++---- .../simcore_service_webserver/catalog_models.py | 14 +++++++------- 4 files changed, 17 insertions(+), 19 deletions(-) diff --git a/packages/models-library/src/models_library/services.py b/packages/models-library/src/models_library/services.py index 5de35afdc930..2b56977bf3ab 100644 --- a/packages/models-library/src/models_library/services.py +++ b/packages/models-library/src/models_library/services.py @@ -51,7 +51,7 @@ # CONSTRAINT TYPES ------------------------------------------- -PropertyName = constr(regex=PROPERTY_KEY_RE) +ServicePortKey = constr(regex=PROPERTY_KEY_RE) FileName = constr(regex=FILENAME_RE) ServiceKey = constr(regex=KEY_RE) @@ -176,7 +176,7 @@ class BaseServiceIOModel(BaseModel): ) # value - file_to_key_map: Optional[dict[FileName, PropertyName]] = Field( + file_to_key_map: Optional[dict[FileName, ServicePortKey]] = Field( None, alias="fileToKeyMap", description="Place the data associated with the named keys in files", @@ -409,8 +409,8 @@ def validate_thumbnail(cls, value): # pylint: disable=no-self-argument,no-self- return value -ServiceInputsDict = dict[PropertyName, ServiceInput] -ServiceOutputsDict = dict[PropertyName, ServiceOutput] +ServiceInputsDict = dict[ServicePortKey, ServiceInput] +ServiceOutputsDict = dict[ServicePortKey, ServiceOutput] class ServiceDockerData(ServiceKeyVersion, _BaseServiceCommonDataModel): diff --git a/services/director-v2/src/simcore_service_director_v2/models/domains/comp_tasks.py b/services/director-v2/src/simcore_service_director_v2/models/domains/comp_tasks.py index 1ad555f42d3d..d4adc6defde9 100644 --- a/services/director-v2/src/simcore_service_director_v2/models/domains/comp_tasks.py +++ b/services/director-v2/src/simcore_service_director_v2/models/domains/comp_tasks.py @@ -1,6 +1,6 @@ from contextlib import suppress from datetime import datetime -from typing import Any, Dict, Optional +from typing import Any, Optional from models_library.basic_regex import VERSION_RE from models_library.errors import ErrorDict @@ -9,9 +9,9 @@ from models_library.projects_state import RunningState from models_library.services import ( KEY_RE, - PropertyName, ServiceInputsDict, ServiceOutput, + ServicePortKey, ) from pydantic import BaseModel, Extra, Field, validator from pydantic.types import PositiveInt @@ -88,7 +88,7 @@ class Config(ServiceOutput.Config): extra = Extra.ignore -_ServiceOutputsOverride = Dict[PropertyName, _ServiceOutputOverride] +_ServiceOutputsOverride = dict[ServicePortKey, _ServiceOutputOverride] class NodeSchema(BaseModel): @@ -133,7 +133,7 @@ def convert_state_from_state_type_enum_if_needed(cls, v): return RunningState(DB_TO_RUNNING_STATE[StateType(v)]) return v - def to_db_model(self, **exclusion_rules) -> Dict[str, Any]: + def to_db_model(self, **exclusion_rules) -> dict[str, Any]: comp_task_dict = self.dict(by_alias=True, exclude_unset=True, **exclusion_rules) if "state" in comp_task_dict: comp_task_dict["state"] = RUNNING_STATE_TO_DB[comp_task_dict["state"]].value diff --git a/services/director-v2/src/simcore_service_director_v2/models/domains/dynamic_services.py b/services/director-v2/src/simcore_service_director_v2/models/domains/dynamic_services.py index aa59b155abfc..54cc67708389 100644 --- a/services/director-v2/src/simcore_service_director_v2/models/domains/dynamic_services.py +++ b/services/director-v2/src/simcore_service_director_v2/models/domains/dynamic_services.py @@ -1,6 +1,4 @@ -from typing import List - -from models_library.services import PropertyName +from models_library.services import ServicePortKey from models_library.services_resources import ( ServiceResourcesDict, ServiceResourcesDictHelpers, @@ -11,7 +9,7 @@ class RetrieveDataIn(BaseModel): - port_keys: List[PropertyName] = Field( + port_keys: list[ServicePortKey] = Field( ..., description="The port keys to retrieve data from" ) diff --git a/services/web/server/src/simcore_service_webserver/catalog_models.py b/services/web/server/src/simcore_service_webserver/catalog_models.py index 8d1543747d8c..4d298a5dc4f2 100644 --- a/services/web/server/src/simcore_service_webserver/catalog_models.py +++ b/services/web/server/src/simcore_service_webserver/catalog_models.py @@ -1,12 +1,12 @@ -from typing import Any, Dict, Optional +from typing import Any, Optional import orjson from models_library.services import ( KEY_RE, VERSION_RE, - PropertyName, ServiceInput, ServiceOutput, + ServicePortKey, ) from models_library.utils.change_case import snake_to_camel from pint import UnitRegistry @@ -17,8 +17,8 @@ ServiceKey = constr(regex=KEY_RE) ServiceVersion = constr(regex=VERSION_RE) -ServiceInputKey = PropertyName -ServiceOutputKey = PropertyName +ServiceInputKey = ServicePortKey +ServiceOutputKey = ServicePortKey def json_dumps(v, *, default=None) -> str: @@ -95,7 +95,7 @@ class Config(_BaseCommonApiExtension.Config): @classmethod def from_catalog_service_api_model( cls, - service: Dict[str, Any], + service: dict[str, Any], input_key: ServiceInputKey, ureg: Optional[UnitRegistry] = None, ): @@ -136,7 +136,7 @@ class Config(_BaseCommonApiExtension.Config): @classmethod def from_catalog_service_api_model( cls, - service: Dict[str, Any], + service: dict[str, Any], output_key: ServiceOutputKey, ureg: Optional[UnitRegistry] = None, ): @@ -166,7 +166,7 @@ def from_catalog_service_api_model( def replace_service_input_outputs( - service: Dict[str, Any], + service: dict[str, Any], *, unit_registry: Optional[UnitRegistry] = None, **export_options,