Skip to content

Commit 5732a12

Browse files
sanderegggiancarloromeoGitHKAndrei Neagupcrespov
authored
⬆️ Pydantic v2 migration (#6578)
Co-authored-by: Giancarlo Romeo <[email protected]> Co-authored-by: Andrei Neagu <[email protected]> Co-authored-by: Andrei Neagu <[email protected]> Co-authored-by: Pedro Crespo-Valero <[email protected]> Co-authored-by: Mads Bisgaard <[email protected]>
1 parent 37c98ea commit 5732a12

File tree

1,383 files changed

+25286
-14745
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,383 files changed

+25286
-14745
lines changed

.env-devel

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ AUTOSCALING_EC2_ACCESS=null
3333
AUTOSCALING_EC2_INSTANCES=null
3434
AUTOSCALING_LOGLEVEL=INFO
3535
AUTOSCALING_NODES_MONITORING=null
36-
AUTOSCALING_POLL_INTERVAL=10
36+
AUTOSCALING_POLL_INTERVAL="00:00:10"
3737
AUTOSCALING_SSM_ACCESS=null
3838
AUTOSCALING_TRACING={}
3939

@@ -120,13 +120,13 @@ DYNAMIC_SIDECAR_IMAGE=${DOCKER_REGISTRY:-itisfoundation}/dynamic-sidecar:${DOCKE
120120
DYNAMIC_SIDECAR_LOG_LEVEL=DEBUG
121121
DYNAMIC_SIDECAR_PROMETHEUS_MONITORING_NETWORKS=[]
122122
DYNAMIC_SIDECAR_PROMETHEUS_SERVICE_LABELS={}
123-
DYNAMIC_SIDECAR_API_SAVE_RESTORE_STATE_TIMEOUT=3600
123+
DYNAMIC_SIDECAR_API_SAVE_RESTORE_STATE_TIMEOUT=01:00:00
124124
DIRECTOR_V2_TRACING={}
125125

126126
# DYNAMIC_SCHEDULER ----
127127
DYNAMIC_SCHEDULER_LOGLEVEL=DEBUG
128128
DYNAMIC_SCHEDULER_PROFILING=1
129-
DYNAMIC_SCHEDULER_STOP_SERVICE_TIMEOUT=PT1H
129+
DYNAMIC_SCHEDULER_STOP_SERVICE_TIMEOUT=01:00:00
130130
DYNAMIC_SCHEDULER_TRACING={}
131131

132132
FUNCTION_SERVICES_AUTHORS='{"UN": {"name": "Unknown", "email": "[email protected]", "affiliation": "unknown"}}'

.github/CODEOWNERS

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ Makefile @pcrespov @sanderegg
1313
/api/ @sanderegg @pcrespov @matusdrobuliak66
1414
/ci/ @sanderegg @pcrespov
1515
/docs/ @pcrespov
16-
/packages/models-library/ @sanderegg @pcrespov @matusdrobuliak66
16+
/packages/common-library/ @giancarloromeo
17+
/packages/models-library/ @sanderegg @pcrespov @matusdrobuliak66 @giancarloromeo
1718
/packages/postgres-database/ @matusdrobuliak66
1819
/packages/pytest-simcore/ @pcrespov @sanderegg
1920
/packages/service-integration/ @pcrespov @sanderegg @GitHK

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

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ jobs:
5454
aws-library: ${{ steps.filter.outputs.aws-library }}
5555
dask-task-models-library: ${{ steps.filter.outputs.dask-task-models-library }}
5656
models-library: ${{ steps.filter.outputs.models-library }}
57+
common-library: ${{ steps.filter.outputs.common-library }}
5758
notifications-library: ${{ steps.filter.outputs.notifications-library }}
5859
postgres-database: ${{ steps.filter.outputs.postgres-database }}
5960
service-integration: ${{ steps.filter.outputs.service-integration }}
@@ -110,6 +111,8 @@ jobs:
110111
- 'services/docker-compose*'
111112
- 'scripts/mypy/*'
112113
- 'mypy.ini'
114+
common-library:
115+
- 'packages/common-library/**'
113116
notifications-library:
114117
- 'packages/notifications-library/**'
115118
- 'packages/postgres-database/**'
@@ -1799,6 +1802,47 @@ jobs:
17991802
with:
18001803
token: ${{ secrets.CODECOV_TOKEN }}
18011804

1805+
unit-test-common-library:
1806+
needs: changes
1807+
if: ${{ needs.changes.outputs.common-library == 'true' || github.event_name == 'push' }}
1808+
timeout-minutes: 18 # if this timeout gets too small, then split the tests
1809+
name: "[unit] common-library"
1810+
runs-on: ${{ matrix.os }}
1811+
strategy:
1812+
matrix:
1813+
python: ["3.11"]
1814+
os: [ubuntu-22.04]
1815+
fail-fast: false
1816+
steps:
1817+
- uses: actions/checkout@v4
1818+
- name: setup docker buildx
1819+
id: buildx
1820+
uses: docker/setup-buildx-action@v3
1821+
with:
1822+
driver: docker-container
1823+
- name: setup python environment
1824+
uses: actions/setup-python@v5
1825+
with:
1826+
python-version: ${{ matrix.python }}
1827+
- name: install uv
1828+
uses: yezz123/setup-uv@v4
1829+
- uses: actions/cache@v4
1830+
id: cache-uv
1831+
with:
1832+
path: ~/.cache/uv
1833+
key: ${{ runner.os }}-${{ github.job }}-python-${{ matrix.python }}-uv
1834+
- name: show system version
1835+
run: ./ci/helpers/show_system_versions.bash
1836+
- name: install
1837+
run: ./ci/github/unit-testing/common-library.bash install
1838+
- name: typecheck
1839+
run: ./ci/github/unit-testing/common-library.bash typecheck
1840+
- name: test
1841+
run: ./ci/github/unit-testing/common-library.bash test
1842+
- uses: codecov/[email protected]
1843+
with:
1844+
flags: unittests #optional
1845+
18021846
unit-test-notifications-library:
18031847
needs: changes
18041848
if: ${{ needs.changes.outputs.notifications-library == 'true' || github.event_name == 'push' }}
@@ -1919,6 +1963,7 @@ jobs:
19191963
unit-test-dynamic-sidecar,
19201964
unit-test-efs-guardian,
19211965
unit-test-models-library,
1966+
unit-test-common-library,
19221967
unit-test-notifications-library,
19231968
unit-test-osparc-gateway-server,
19241969
unit-test-payments,

api/specs/web-server/_common.py

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@
88
from typing import Any, ClassVar, NamedTuple
99

1010
import yaml
11+
from common_library.json_serialization import json_dumps
12+
from common_library.pydantic_fields_extension import get_type
1113
from fastapi import FastAPI, Query
1214
from models_library.basic_types import LogLevel
13-
from models_library.utils.json_serialization import json_dumps
1415
from pydantic import BaseModel, Field, create_model
1516
from pydantic.fields import FieldInfo
1617
from servicelib.fastapi.openapi import override_fastapi_openapi_method
@@ -37,31 +38,28 @@ def __modify_schema__(cls, field_schema: dict[str, Any]) -> None:
3738

3839
def as_query(model_class: type[BaseModel]) -> type[BaseModel]:
3940
fields = {}
40-
for field_name, model_field in model_class.__fields__.items():
41+
for field_name, field_info in model_class.model_fields.items():
4142

42-
field_type = model_field.type_
43-
default_value = model_field.default
43+
field_type = get_type(field_info)
44+
default_value = field_info.default
4445

4546
kwargs = {
46-
"alias": model_field.field_info.alias,
47-
"title": model_field.field_info.title,
48-
"description": model_field.field_info.description,
49-
"gt": model_field.field_info.gt,
50-
"ge": model_field.field_info.ge,
51-
"lt": model_field.field_info.lt,
52-
"le": model_field.field_info.le,
53-
"min_length": model_field.field_info.min_length,
54-
"max_length": model_field.field_info.max_length,
55-
"regex": model_field.field_info.regex,
56-
**model_field.field_info.extra,
47+
"alias": field_info.alias,
48+
"title": field_info.title,
49+
"description": field_info.description,
50+
"metadata": field_info.metadata,
51+
"json_schema_extra": field_info.json_schema_extra,
5752
}
5853

5954
if issubclass(field_type, BaseModel):
6055
# Complex fields
56+
assert "json_schema_extra" in kwargs # nosec
57+
assert kwargs["json_schema_extra"] # nosec
6158
field_type = _create_json_type(
6259
description=kwargs["description"],
63-
example=kwargs.get("example_json"),
60+
example=kwargs.get("json_schema_extra", {}).get("example_json"),
6461
)
62+
6563
default_value = json_dumps(default_value) if default_value else None
6664

6765
fields[field_name] = (field_type, Query(default=default_value, **kwargs))
@@ -147,7 +145,7 @@ def create_and_save_openapi_specs(
147145
)
148146
with file_path.open("wt") as fh:
149147
yaml.safe_dump(openapi, fh, indent=1, sort_keys=False)
150-
print("Saved OAS to", file_path)
148+
print("Saved OAS to", file_path) # noqa: T201
151149

152150

153151
class ParamSpec(NamedTuple):
@@ -169,8 +167,8 @@ def assert_handler_signature_against_model(
169167

170168
# query and path parameters
171169
implemented_params = [
172-
ParamSpec(field.name, field.type_, field.field_info)
173-
for field in model_cls.__fields__.values()
170+
ParamSpec(name, get_type(info), info)
171+
for name, info in model_cls.model_fields.items()
174172
]
175173

176174
implemented_names = {p.name for p in implemented_params}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/bin/bash
2+
# http://redsymbol.net/articles/unofficial-bash-strict-mode/
3+
set -o errexit # abort on nonzero exitstatus
4+
set -o nounset # abort on unbound variable
5+
set -o pipefail # don't hide errors within pipes
6+
IFS=$'\n\t'
7+
8+
install() {
9+
make devenv
10+
# shellcheck source=/dev/null
11+
source .venv/bin/activate
12+
pushd packages/common-library
13+
make install-ci
14+
popd
15+
uv pip list
16+
}
17+
18+
test() {
19+
# shellcheck source=/dev/null
20+
source .venv/bin/activate
21+
pushd packages/common-library
22+
make tests-ci
23+
popd
24+
}
25+
26+
typecheck() {
27+
# shellcheck source=/dev/null
28+
source .venv/bin/activate
29+
uv pip install mypy
30+
pushd packages/common-library
31+
make mypy
32+
popd
33+
}
34+
35+
# Check if the function exists (bash specific)
36+
if declare -f "$1" >/dev/null; then
37+
# call arguments verbatim
38+
"$@"
39+
else
40+
# Show a helpful error
41+
echo "'$1' is not a known function name" >&2
42+
exit 1
43+
fi

ci/helpers/requirements.txt

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
# This file was autogenerated by uv via the following command:
2-
# uv pip compile requirements.in
2+
# uv pip compile requirements.in -o requirements.txt
33
aiohttp==3.9.5
4+
# via
5+
# -c ../../requirements/constraints.txt
6+
# -r requirements.in
47
aiosignal==1.3.1
58
# via aiohttp
9+
annotated-types==0.7.0
10+
# via pydantic
611
anyio==4.3.0
712
# via starlette
8-
async-timeout==4.0.3
9-
# via aiohttp
1013
attrs==23.2.0
1114
# via aiohttp
12-
exceptiongroup==1.2.1
13-
# via anyio
14-
fastapi==0.99.1
15+
fastapi==0.115.0
16+
# via -r requirements.in
1517
frozenlist==1.4.1
1618
# via
1719
# aiohttp
@@ -24,16 +26,22 @@ multidict==6.0.5
2426
# via
2527
# aiohttp
2628
# yarl
27-
pydantic==1.10.15
28-
# via fastapi
29+
pydantic==2.9.2
30+
# via
31+
# -c ../../requirements/constraints.txt
32+
# fastapi
33+
pydantic-core==2.23.4
34+
# via pydantic
2935
sniffio==1.3.1
3036
# via anyio
31-
starlette==0.27.0
32-
# via fastapi
37+
starlette==0.38.6
38+
# via
39+
# -c ../../requirements/constraints.txt
40+
# fastapi
3341
typing-extensions==4.11.0
3442
# via
35-
# anyio
3643
# fastapi
3744
# pydantic
45+
# pydantic-core
3846
yarl==1.9.4
3947
# via aiohttp

packages/aws-library/requirements/_base.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# Specifies third-party dependencies for 'aws-library'
33
#
44
--constraint ../../../requirements/constraints.txt
5+
--requirement ../../../packages/common-library/requirements/_base.in
56
--requirement ../../../packages/models-library/requirements/_base.in
67
--requirement ../../../packages/service-library/requirements/_base.in
78
--requirement ../../../packages/settings-library/requirements/_base.in

0 commit comments

Comments
 (0)