From fade298e05d7a95e3aa12939794f0b290d31c57d Mon Sep 17 00:00:00 2001 From: Pedro Crespo-Valero <32402063+pcrespov@users.noreply.github.com> Date: Tue, 3 Dec 2024 09:52:43 +0100 Subject: [PATCH] basic types --- packages/common-library/src/common_library/basic_types.py | 7 +++++++ packages/models-library/src/models_library/_compat.py | 6 ------ .../models-library/src/models_library/app_diagnostics.py | 3 +-- packages/models-library/src/models_library/projects.py | 2 +- .../models-library/src/models_library/projects_nodes.py | 2 +- .../src/service_integration/osparc_config.py | 2 +- packages/settings-library/tests/test_base.py | 7 +++++-- 7 files changed, 16 insertions(+), 13 deletions(-) delete mode 100644 packages/models-library/src/models_library/_compat.py diff --git a/packages/common-library/src/common_library/basic_types.py b/packages/common-library/src/common_library/basic_types.py index ab5278cd4f4..6964e6c4033 100644 --- a/packages/common-library/src/common_library/basic_types.py +++ b/packages/common-library/src/common_library/basic_types.py @@ -1,5 +1,12 @@ from enum import StrEnum +from pydantic_core import PydanticUndefined + +# SEE https://github.com/fastapi/fastapi/blob/master/fastapi/_compat.py#L75-L78 +# +# Use as default when default_factory +Undefined = PydanticUndefined + class LogLevel(StrEnum): DEBUG = "DEBUG" diff --git a/packages/models-library/src/models_library/_compat.py b/packages/models-library/src/models_library/_compat.py deleted file mode 100644 index 1079ccef28a..00000000000 --- a/packages/models-library/src/models_library/_compat.py +++ /dev/null @@ -1,6 +0,0 @@ -from pydantic_core import PydanticUndefined - -# SEE https://github.com/fastapi/fastapi/blob/master/fastapi/_compat.py#L75-L78 -# -# Use as default when default_factory -Undefined = PydanticUndefined diff --git a/packages/models-library/src/models_library/app_diagnostics.py b/packages/models-library/src/models_library/app_diagnostics.py index 1f90bead808..fe0c77cbafb 100644 --- a/packages/models-library/src/models_library/app_diagnostics.py +++ b/packages/models-library/src/models_library/app_diagnostics.py @@ -1,9 +1,8 @@ from typing import Annotated, Any +from common_library.basic_types import Undefined from pydantic import AnyUrl, BaseModel, Field -from ._compat import Undefined - _Unset: Any = Undefined diff --git a/packages/models-library/src/models_library/projects.py b/packages/models-library/src/models_library/projects.py index 4776e84bce3..45db325b0da 100644 --- a/packages/models-library/src/models_library/projects.py +++ b/packages/models-library/src/models_library/projects.py @@ -7,12 +7,12 @@ from typing import Annotated, Any, Final, TypeAlias from uuid import UUID +from common_library.basic_types import Undefined from models_library.basic_types import ConstrainedStr from models_library.folders import FolderID from models_library.workspaces import WorkspaceID from pydantic import BaseModel, ConfigDict, Field, HttpUrl, field_validator -from ._compat import Undefined from .basic_regex import DATE_RE, UUID_RE_BASE from .emails import LowerCaseEmailStr from .projects_access import AccessRights, GroupIDStr diff --git a/packages/models-library/src/models_library/projects_nodes.py b/packages/models-library/src/models_library/projects_nodes.py index 6ff1d8c1a4e..ebbc39045e4 100644 --- a/packages/models-library/src/models_library/projects_nodes.py +++ b/packages/models-library/src/models_library/projects_nodes.py @@ -5,6 +5,7 @@ from copy import deepcopy from typing import Annotated, Any, TypeAlias, Union +from common_library.basic_types import Undefined from pydantic import ( BaseModel, ConfigDict, @@ -18,7 +19,6 @@ field_validator, ) -from ._compat import Undefined from .basic_types import EnvVarKey, KeyIDStr from .projects_access import AccessEnum from .projects_nodes_io import ( diff --git a/packages/service-integration/src/service_integration/osparc_config.py b/packages/service-integration/src/service_integration/osparc_config.py index e5a69a87f95..f9e22e653cb 100644 --- a/packages/service-integration/src/service_integration/osparc_config.py +++ b/packages/service-integration/src/service_integration/osparc_config.py @@ -16,7 +16,7 @@ from pathlib import Path from typing import Annotated, Any, Final, Literal -from models_library._compat import Undefined +from common_library.basic_types import Undefined from models_library.basic_types import SHA256Str from models_library.callbacks_mapping import CallbacksMapping from models_library.service_settings_labels import ( diff --git a/packages/settings-library/tests/test_base.py b/packages/settings-library/tests/test_base.py index 879bf5868be..d4ebd987760 100644 --- a/packages/settings-library/tests/test_base.py +++ b/packages/settings-library/tests/test_base.py @@ -8,6 +8,7 @@ from collections.abc import Callable from typing import Any +import pydantic import pytest import settings_library.base from pydantic import BaseModel, ValidationError @@ -23,6 +24,8 @@ ) from settings_library.email import SMTPSettings +pydantic_version = ".".join(pydantic.__version__.split(".")[:2]) + S2 = json.dumps({"S_VALUE": 2}) S3 = json.dumps({"S_VALUE": 3}) @@ -180,7 +183,7 @@ def test_create_settings_class_without_environ_fails( "loc": ("S_VALUE",), "msg": "Field required", "type": "missing", - "url": "https://errors.pydantic.dev/2.9/v/missing", + "url": f"https://errors.pydantic.dev/{pydantic_version}/v/missing", } @@ -310,7 +313,7 @@ class SettingsClassExt(SettingsClass): "loc": ("INT_VALUE_TO_NOTHING",), "msg": "Input should be a valid integer, unable to parse string as an integer", "type": "int_parsing", - "url": "https://errors.pydantic.dev/2.9/v/int_parsing", + "url": f"https://errors.pydantic.dev/{pydantic_version}/v/int_parsing", }