Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

⬆️ Upgrade libraries (pydantic v2) #6366

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
210 commits
Select commit Hold shift + click to select a range
dcb5895
upgrade aws-library
giancarloromeo Sep 16, 2024
3620668
upgrade dask-task-models-library
giancarloromeo Sep 16, 2024
85dffd8
upgrade notifications-library
giancarloromeo Sep 16, 2024
17b9457
upgrade postgres-database
giancarloromeo Sep 16, 2024
9571d2f
upgrade service-library
giancarloromeo Sep 16, 2024
bff67e6
upgrade simcore-sdk
giancarloromeo Sep 16, 2024
17681a5
upgrade settings-library
giancarloromeo Sep 16, 2024
81c045b
upgrade service-integration
giancarloromeo Sep 16, 2024
3f4901e
upgrade settings-library
giancarloromeo Sep 16, 2024
a0f2890
add type hint
giancarloromeo Sep 17, 2024
e1ac2c6
continue upgrading
giancarloromeo Sep 17, 2024
92175f8
Merge branch 'pydantic_v2_migration' into is4481/upgrade-libs
giancarloromeo Sep 18, 2024
7f3801a
continue upgrading
giancarloromeo Sep 18, 2024
a470e9e
continue upgrading
giancarloromeo Sep 18, 2024
8652f39
update base requirements
giancarloromeo Sep 18, 2024
7b3c39e
continue upgrading
giancarloromeo Sep 18, 2024
2fe2b81
replace deprecated parse_obj methods
giancarloromeo Sep 18, 2024
f320883
replace deprecated dict methods
giancarloromeo Sep 18, 2024
2b6180c
replace deprecated json methods
giancarloromeo Sep 19, 2024
c88b393
replace deprecated parse_obj_as methods
giancarloromeo Sep 19, 2024
ceb9f69
update model config access
giancarloromeo Sep 19, 2024
e0bc99b
update pydantic settings test
giancarloromeo Sep 19, 2024
18b7e37
upgrade base module
giancarloromeo Sep 19, 2024
dc3d602
fix ByteSize values
giancarloromeo Sep 19, 2024
724bed4
replace deprecated parse_obj_as method
giancarloromeo Sep 19, 2024
f2f007e
fix regex validation with look-ahead assertion
giancarloromeo Sep 19, 2024
76f1d5e
fix validate tag_key
giancarloromeo Sep 19, 2024
2112122
remove deprecated
giancarloromeo Sep 19, 2024
7404f3e
continue upgrading
giancarloromeo Sep 19, 2024
7e156d7
fix regex
giancarloromeo Sep 20, 2024
1401f2e
fix error base class
giancarloromeo Sep 20, 2024
5f553ce
continue upgrading
giancarloromeo Sep 20, 2024
6ed0551
upgrade dependencies
giancarloromeo Sep 20, 2024
c36b542
fix error base class
giancarloromeo Sep 20, 2024
49a0ab4
upgrade dependencies
giancarloromeo Sep 20, 2024
0191717
continue upgrading
giancarloromeo Sep 20, 2024
2e74551
upgrade dependencies
giancarloromeo Sep 20, 2024
c4e6fb2
fix email model validator
giancarloromeo Sep 20, 2024
0846266
ignore code type
giancarloromeo Sep 20, 2024
5601125
fix validate_call
giancarloromeo Sep 20, 2024
d47edd0
fix validate call
giancarloromeo Sep 20, 2024
6f38de2
fix faker types
giancarloromeo Sep 20, 2024
e69b9ef
continue upgrading
giancarloromeo Sep 20, 2024
9f17d51
continue upgrading
giancarloromeo Sep 20, 2024
d13f0e0
continue upgrading
giancarloromeo Sep 20, 2024
ef0e355
fix endpoint_url type
giancarloromeo Sep 20, 2024
6c30f36
fix mock
giancarloromeo Sep 20, 2024
3d734e0
fix endpoint_url type
giancarloromeo Sep 20, 2024
c667921
remove unused type ignore
giancarloromeo Sep 20, 2024
4fb2bf2
update error base class
giancarloromeo Sep 20, 2024
c11f109
fix folders error
giancarloromeo Sep 20, 2024
68fa4ae
use common osparcerrormixin
giancarloromeo Sep 20, 2024
40a4627
continue upgrading
giancarloromeo Sep 20, 2024
0563d81
upgrade dependencies
giancarloromeo Sep 20, 2024
2094d4f
continue upgrading
giancarloromeo Sep 20, 2024
57b0710
continue upgrading
giancarloromeo Sep 20, 2024
29306b1
continue upgrading
giancarloromeo Sep 22, 2024
a9c3ef3
remove deprecated parse_obj_as
giancarloromeo Sep 23, 2024
8250aff
fix url type
giancarloromeo Sep 23, 2024
6c63ccf
fix url type
giancarloromeo Sep 23, 2024
fd2f6cb
fix rabbit settings
giancarloromeo Sep 23, 2024
7a888f5
upgrade deprecated method
giancarloromeo Sep 23, 2024
b43955c
fix dns* creation
giancarloromeo Sep 23, 2024
a1a7e24
return redis dns as str
giancarloromeo Sep 23, 2024
d74f380
upgrade pydantic dependencies
giancarloromeo Sep 23, 2024
40e34e5
continue upgrading
giancarloromeo Sep 23, 2024
2843a12
continue upgrading
giancarloromeo Sep 23, 2024
c82afa5
fix anyhttpurl validation
giancarloromeo Sep 23, 2024
c96cd21
continue upgrading
giancarloromeo Sep 23, 2024
dfe63b5
continue upgrading
giancarloromeo Sep 23, 2024
0df8f60
add ignore
giancarloromeo Sep 23, 2024
56c1c89
fix errors messages
giancarloromeo Sep 23, 2024
3b15198
continue upgrading
giancarloromeo Sep 23, 2024
bb10a3d
continue upgrading
giancarloromeo Sep 23, 2024
ec0404a
continue upgrading
giancarloromeo Sep 23, 2024
96a0663
continue upgrading
giancarloromeo Sep 23, 2024
ad7ddb5
continue upgrading
giancarloromeo Sep 23, 2024
6369b33
fix test
giancarloromeo Sep 23, 2024
7d5537d
continue upgrading
giancarloromeo Sep 23, 2024
486437d
update error msg
giancarloromeo Sep 23, 2024
0167480
fix model_fields iteration
giancarloromeo Sep 23, 2024
1409f87
fix labels type
giancarloromeo Sep 23, 2024
94749e6
fix root field reference
giancarloromeo Sep 23, 2024
223e2ac
continue upgrading
giancarloromeo Sep 23, 2024
a9d30ab
fix test
giancarloromeo Sep 23, 2024
2a497f3
remove deprecated method
giancarloromeo Sep 23, 2024
32318b0
fix error output
giancarloromeo Sep 23, 2024
45baff8
fix base settings
giancarloromeo Sep 24, 2024
81f80de
fix error
giancarloromeo Sep 24, 2024
1c33bfb
fix error class
giancarloromeo Sep 24, 2024
898155d
fix nullable
giancarloromeo Sep 24, 2024
e3fc9c5
update base
giancarloromeo Sep 24, 2024
e645331
update test
giancarloromeo Sep 24, 2024
ff5533b
restore Error type
giancarloromeo Sep 24, 2024
0eaa8c8
update test
giancarloromeo Sep 24, 2024
9c22d2b
force mode_rebuild
giancarloromeo Sep 25, 2024
4e74ec7
fix port type
giancarloromeo Sep 25, 2024
0e3f7d3
continue upgrading
giancarloromeo Sep 25, 2024
6aaaea1
continue upgrading
giancarloromeo Sep 25, 2024
4ddddc9
fix AnyUrl build
giancarloromeo Sep 25, 2024
8120fff
fix field_info
giancarloromeo Sep 25, 2024
a28234d
fix utils service
giancarloromeo Sep 25, 2024
da97728
fix mypy
giancarloromeo Sep 25, 2024
06912be
set optional
giancarloromeo Sep 25, 2024
a0d6f84
set optional
giancarloromeo Sep 25, 2024
8e62f69
continue upgrading
giancarloromeo Sep 25, 2024
e3510cd
continue upgrading
giancarloromeo Sep 25, 2024
3e8ca5d
continue upgrading
giancarloromeo Sep 25, 2024
fffb812
fix cached property
giancarloromeo Sep 25, 2024
e5f9263
remove pytest.mark
giancarloromeo Sep 25, 2024
bc208a2
fix mypy
giancarloromeo Sep 26, 2024
85eb86f
fix parse none env
giancarloromeo Sep 26, 2024
476e538
fix env list parsing
giancarloromeo Sep 26, 2024
f28c414
use BeforeValidator for country codes
giancarloromeo Sep 26, 2024
5d4a6a2
fix mypy
giancarloromeo Sep 26, 2024
1283488
fix utils cli
giancarloromeo Sep 27, 2024
5cecc63
fix encoder issues
giancarloromeo Sep 27, 2024
cbc556f
add requirements
giancarloromeo Sep 27, 2024
4c27843
skip missing data
giancarloromeo Sep 27, 2024
9c4e07e
fix import
giancarloromeo Sep 27, 2024
6c58ae5
fix option name
giancarloromeo Sep 27, 2024
76b5cba
continue ugrading
giancarloromeo Sep 27, 2024
7021117
firx param name
giancarloromeo Sep 27, 2024
cd1fbc1
fix mypy
giancarloromeo Sep 30, 2024
4a29d2e
fix mypy
giancarloromeo Sep 30, 2024
532206e
fix rootmodel
giancarloromeo Sep 30, 2024
2cddbd8
continue upgrading
giancarloromeo Sep 30, 2024
32a5453
continue upgrading
giancarloromeo Sep 30, 2024
57f65d5
fix serializer
giancarloromeo Sep 30, 2024
02d950e
fix mypy
giancarloromeo Sep 30, 2024
16a9740
run bump-pydantic
giancarloromeo Sep 30, 2024
04509d3
fix int test
giancarloromeo Sep 30, 2024
10a80b3
fix rabbit method name
giancarloromeo Oct 1, 2024
3f91e30
remove deprecated
giancarloromeo Oct 1, 2024
9ebf506
replace deprecated dict
giancarloromeo Oct 1, 2024
94c33aa
fix field
giancarloromeo Oct 1, 2024
12ec0a3
upgrade requirements
giancarloromeo Oct 2, 2024
ca36539
fix pylint
giancarloromeo Oct 2, 2024
4e49d2d
fix endopoints type
giancarloromeo Oct 2, 2024
f0fc1d7
fix pagination urls type
giancarloromeo Oct 2, 2024
aa6a73f
fix sonar
giancarloromeo Oct 2, 2024
5debf98
fix code smells
giancarloromeo Oct 2, 2024
9d93d7e
continue upgrading
giancarloromeo Oct 2, 2024
0a1a1a4
continue upgrading
giancarloromeo Oct 2, 2024
32622e0
fix mypy
giancarloromeo Oct 2, 2024
9a6df80
move adapter out
giancarloromeo Oct 2, 2024
8e53f7a
move adapter out
giancarloromeo Oct 2, 2024
9f1c18c
simplify regex
giancarloromeo Oct 2, 2024
1df1179
fix field name
giancarloromeo Oct 3, 2024
9e99c51
fix validationerror match
giancarloromeo Oct 3, 2024
b07d12b
fix optional field
giancarloromeo Oct 3, 2024
444a600
fix comments
giancarloromeo Oct 3, 2024
2a8d6eb
remove redundant comment
giancarloromeo Oct 3, 2024
386c316
remove unnecessary schema patch
giancarloromeo Oct 3, 2024
68b1599
upgrade CI requrements
giancarloromeo Oct 3, 2024
3aa9009
remove unnecessary cast
giancarloromeo Oct 3, 2024
24679c1
add final
giancarloromeo Oct 4, 2024
c9f094f
fix ValidationError import
giancarloromeo Oct 4, 2024
fee36c0
fix mypy
giancarloromeo Oct 4, 2024
79a4641
fix missing callback
giancarloromeo Oct 4, 2024
06c8046
fix field name
giancarloromeo Oct 4, 2024
323dbc9
code not used by base class
giancarloromeo Oct 4, 2024
9a8e718
revert latest commit
giancarloromeo Oct 4, 2024
42f07ea
set final
giancarloromeo Oct 4, 2024
968b5ab
Add common library
giancarloromeo Oct 7, 2024
67304b6
add code field
giancarloromeo Oct 7, 2024
0ce5ef4
fix pylint
giancarloromeo Oct 7, 2024
3f5d881
add base common library
giancarloromeo Oct 7, 2024
df864b4
add error classes
giancarloromeo Oct 7, 2024
09c0073
point to common library
giancarloromeo Oct 7, 2024
d752d18
fix names
giancarloromeo Oct 7, 2024
3f0ec86
remove moved modules
giancarloromeo Oct 7, 2024
4a30d09
fix rename
giancarloromeo Oct 7, 2024
1e57220
add utils
giancarloromeo Oct 7, 2024
cb7ac13
add common modules
giancarloromeo Oct 7, 2024
30e2613
Merge branch 'add-common-library' into is4481/upgrade-libs
giancarloromeo Oct 7, 2024
2663ed1
update requirements
giancarloromeo Oct 7, 2024
e358cd2
upgrade package name
giancarloromeo Oct 7, 2024
0b8a6ab
remove moved modules
giancarloromeo Oct 7, 2024
2b4e79d
update requirements
giancarloromeo Oct 7, 2024
e6efb6d
update requirements
giancarloromeo Oct 7, 2024
51c6ca5
update requirements
giancarloromeo Oct 7, 2024
4265fec
update package name
giancarloromeo Oct 7, 2024
5a998a0
add requirement
giancarloromeo Oct 7, 2024
fc91024
add requirement
giancarloromeo Oct 7, 2024
0ead0b4
update requirements
giancarloromeo Oct 7, 2024
727c634
add py.typed
giancarloromeo Oct 7, 2024
f387ebb
add me as codeowner
giancarloromeo Oct 7, 2024
5ed512a
update requirements
giancarloromeo Oct 7, 2024
7bc8715
update requirements
giancarloromeo Oct 7, 2024
18ad6d1
update requirements
giancarloromeo Oct 7, 2024
f63a537
minor fixes
giancarloromeo Oct 7, 2024
97854a0
Merge branch 'add-common-library' into is4481/upgrade-libs
giancarloromeo Oct 7, 2024
4b93c00
use anyhttpurl legacy
giancarloromeo Oct 7, 2024
9114d67
Merge branch 'pydantic_v2_migration' into is4481/upgrade-libs
giancarloromeo Oct 7, 2024
989e76a
upgrade reqs
giancarloromeo Oct 7, 2024
fa7072d
update reqs
giancarloromeo Oct 7, 2024
e36b18c
move changes
giancarloromeo Oct 8, 2024
fdd19c6
move base type adapters
giancarloromeo Oct 8, 2024
c913551
fix test
giancarloromeo Oct 8, 2024
890583b
fix type
giancarloromeo Oct 8, 2024
ffd0adc
fix type
giancarloromeo Oct 8, 2024
7663205
fix networks types
giancarloromeo Oct 9, 2024
74330ed
update reqs
giancarloromeo Oct 9, 2024
26348d0
fix type
giancarloromeo Oct 9, 2024
6eb3bf7
fix type
giancarloromeo Oct 9, 2024
b3d0076
fix url types
giancarloromeo Oct 9, 2024
4606e1f
add type hints
giancarloromeo Oct 9, 2024
a37efc1
fix minor
giancarloromeo Oct 9, 2024
638a0be
add validation
giancarloromeo Oct 9, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 19 additions & 11 deletions ci/helpers/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
# This file was autogenerated by uv via the following command:
# uv pip compile requirements.in
# uv pip compile requirements.in -o requirements.txt
aiohttp==3.9.5
# via
# -c ../../requirements/constraints.txt
# -r requirements.in
aiosignal==1.3.1
# via aiohttp
annotated-types==0.7.0
# via pydantic
anyio==4.3.0
# via starlette
async-timeout==4.0.3
# via aiohttp
attrs==23.2.0
# via aiohttp
exceptiongroup==1.2.1
# via anyio
fastapi==0.99.1
fastapi==0.115.0
# via -r requirements.in
frozenlist==1.4.1
# via
# aiohttp
Expand All @@ -24,16 +26,22 @@ multidict==6.0.5
# via
# aiohttp
# yarl
pydantic==1.10.15
# via fastapi
pydantic==2.9.2
# via
# -c ../../requirements/constraints.txt
# fastapi
pydantic-core==2.23.4
# via pydantic
sniffio==1.3.1
# via anyio
starlette==0.27.0
# via fastapi
starlette==0.38.6
# via
# -c ../../requirements/constraints.txt
# fastapi
typing-extensions==4.11.0
# via
# anyio
# fastapi
# pydantic
# pydantic-core
yarl==1.9.4
# via aiohttp
21 changes: 20 additions & 1 deletion packages/aws-library/requirements/_base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ aiormq==6.8.0
# via aio-pika
aiosignal==1.3.1
# via aiohttp
annotated-types==0.7.0
# via pydantic
anyio==4.4.0
# via
# fast-depends
Expand Down Expand Up @@ -105,7 +107,7 @@ orjson==3.10.7
# -r requirements/../../../packages/service-library/requirements/../../../packages/models-library/requirements/_base.in
pamqp==3.3.0
# via aiormq
pydantic==1.10.17
pydantic==2.9.1
# via
# -c requirements/../../../packages/models-library/requirements/../../../requirements/constraints.txt
# -c requirements/../../../packages/service-library/requirements/../../../packages/models-library/requirements/../../../requirements/constraints.txt
Expand All @@ -120,6 +122,20 @@ pydantic==1.10.17
# -r requirements/../../../packages/settings-library/requirements/_base.in
# -r requirements/_base.in
# fast-depends
# pydantic-extra-types
# pydantic-settings
pydantic-core==2.23.3
# via pydantic
pydantic-extra-types==2.9.0
# via
# -r requirements/../../../packages/models-library/requirements/_base.in
# -r requirements/../../../packages/service-library/requirements/../../../packages/models-library/requirements/_base.in
pydantic-settings==2.5.2
# via
# -r requirements/../../../packages/models-library/requirements/_base.in
# -r requirements/../../../packages/service-library/requirements/../../../packages/models-library/requirements/_base.in
# -r requirements/../../../packages/service-library/requirements/../../../packages/settings-library/requirements/_base.in
# -r requirements/../../../packages/settings-library/requirements/_base.in
pygments==2.18.0
# via rich
pyinstrument==4.7.2
Expand All @@ -128,6 +144,8 @@ python-dateutil==2.9.0.post0
# via
# arrow
# botocore
python-dotenv==1.0.1
# via pydantic-settings
pyyaml==6.0.2
# via
# -c requirements/../../../packages/models-library/requirements/../../../requirements/constraints.txt
Expand Down Expand Up @@ -198,6 +216,7 @@ typing-extensions==4.12.2
# aiodebug
# faststream
# pydantic
# pydantic-core
# typer
# types-aiobotocore
# types-aiobotocore-ec2
Expand Down
15 changes: 13 additions & 2 deletions packages/aws-library/requirements/_test.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
annotated-types==0.7.0
# via
# -c requirements/_base.txt
# pydantic
antlr4-python3-runtime==4.13.2
# via moto
appdirs==1.4.4
Expand Down Expand Up @@ -151,11 +155,15 @@ py-partiql-parser==0.5.5
# via moto
pycparser==2.22
# via cffi
pydantic==1.10.17
pydantic==2.9.1
# via
# -c requirements/../../../requirements/constraints.txt
# -c requirements/_base.txt
# aws-sam-translator
pydantic-core==2.23.3
# via
# -c requirements/_base.txt
# pydantic
pyparsing==3.1.2
# via moto
pytest==8.3.2
Expand Down Expand Up @@ -193,7 +201,9 @@ python-dateutil==2.9.0.post0
# faker
# moto
python-dotenv==1.0.1
# via -r requirements/_test.in
# via
# -c requirements/_base.txt
# -r requirements/_test.in
pyyaml==6.0.2
# via
# -c requirements/../../../requirements/constraints.txt
Expand Down Expand Up @@ -268,6 +278,7 @@ typing-extensions==4.12.2
# flexparser
# pint
# pydantic
# pydantic-core
# types-aioboto3
# types-aiobotocore
urllib3==2.2.2
Expand Down
3 changes: 2 additions & 1 deletion packages/aws-library/requirements/ci.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@
--requirement _test.txt

# installs this repo's packages
simcore-common-library @ ../common-library
simcore-models-library @ ../models-library/
pytest-simcore @ ../pytest-simcore
simcore-models-library @ ../models-library
simcore-service-library @ ../service-library/
simcore-settings-library @ ../settings-library/

Expand Down
3 changes: 2 additions & 1 deletion packages/aws-library/requirements/dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@
--requirement _tools.txt

# installs this repo's packages
--editable ../pytest-simcore
--editable ../common-library/
--editable ../models-library/
--editable ../pytest-simcore/
--editable ../service-library/
--editable ../settings-library/

Expand Down
8 changes: 8 additions & 0 deletions packages/aws-library/src/aws_library/ec2/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
from ._client import SimcoreEC2API
from ._errors import EC2AccessError, EC2NotConnectedError, EC2RuntimeError
from ._models import (
AWS_TAG_KEY_MAX_LENGTH,
AWS_TAG_KEY_MIN_LENGTH,
AWS_TAG_VALUE_MAX_LENGTH,
AWS_TAG_VALUE_MIN_LENGTH,
AWSTagKey,
AWSTagValue,
EC2InstanceBootSpecific,
Expand All @@ -14,6 +18,10 @@
__all__: tuple[str, ...] = (
"AWSTagKey",
"AWSTagValue",
"AWS_TAG_KEY_MIN_LENGTH",
"AWS_TAG_KEY_MAX_LENGTH",
"AWS_TAG_VALUE_MIN_LENGTH",
"AWS_TAG_VALUE_MAX_LENGTH",
"EC2AccessError",
"EC2InstanceBootSpecific",
"EC2InstanceConfig",
Expand Down
7 changes: 2 additions & 5 deletions packages/aws-library/src/aws_library/ec2/_errors.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
# pylint: disable=too-many-ancestors
from typing import Any

from models_library.errors_classes import OsparcErrorMixin
from common_library.errors_classes import OsparcErrorMixin


class EC2BaseError(OsparcErrorMixin, Exception):
def __init__(self, **ctx: Any) -> None:
super().__init__(**ctx)
pass


class EC2RuntimeError(EC2BaseError, RuntimeError):
Expand Down
84 changes: 49 additions & 35 deletions packages/aws-library/src/aws_library/ec2/_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,19 @@
import re
import tempfile
from dataclasses import dataclass
from typing import Any, ClassVar, TypeAlias
from typing import Annotated, Final, TypeAlias

import sh # type: ignore[import-untyped]
from models_library.docker import DockerGenericTag
from pydantic import (
BaseModel,
ByteSize,
ConstrainedStr,
ConfigDict,
Field,
NonNegativeFloat,
NonNegativeInt,
validator,
StringConstraints,
field_validator,
)
from types_aiobotocore_ec2.literals import InstanceStateNameType, InstanceTypeType

Expand All @@ -33,26 +34,26 @@ def __gt__(self, other: "Resources") -> bool:
return self.cpus > other.cpus or self.ram > other.ram

def __add__(self, other: "Resources") -> "Resources":
return Resources.construct(
return Resources.model_construct(
**{
key: a + b
for (key, a), b in zip(
self.dict().items(), other.dict().values(), strict=True
self.model_dump().items(), other.model_dump().values(), strict=True
)
}
)

def __sub__(self, other: "Resources") -> "Resources":
return Resources.construct(
return Resources.model_construct(
**{
key: a - b
for (key, a), b in zip(
self.dict().items(), other.dict().values(), strict=True
self.model_dump().items(), other.model_dump().values(), strict=True
)
}
)

@validator("cpus", pre=True)
@field_validator("cpus", mode="before")
@classmethod
def _floor_cpus_to_0(cls, v: float) -> float:
return max(v, 0)
Expand All @@ -67,19 +68,31 @@ class EC2InstanceType:
InstancePrivateDNSName: TypeAlias = str


class AWSTagKey(ConstrainedStr):
AWS_TAG_KEY_MIN_LENGTH: Final[int] = 1
AWS_TAG_KEY_MAX_LENGTH: Final[int] = 128
Comment on lines +71 to +72
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would dlclare them at the top of the file as it is common convention in python

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, forgot there :)

AWSTagKey: TypeAlias = Annotated[
# see [https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/Using_Tags.html#tag-restrictions]
regex = re.compile(r"^(?!(_index|\.{1,2})$)[a-zA-Z0-9\+\-=\._:@]+$")
min_length = 1
max_length = 128


class AWSTagValue(ConstrainedStr):
str,
StringConstraints(
min_length=AWS_TAG_KEY_MIN_LENGTH,
max_length=AWS_TAG_KEY_MAX_LENGTH,
pattern=re.compile(r"^(?!(_index|\.{1,2})$)[a-zA-Z0-9\+\-=\._:@]+$"),
),
]


AWS_TAG_VALUE_MIN_LENGTH: Final[int] = 0
AWS_TAG_VALUE_MAX_LENGTH: Final[int] = 256
Comment on lines +84 to +85
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

declare on the top of the file

AWSTagValue: TypeAlias = Annotated[
# see [https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/Using_Tags.html#tag-restrictions]
# quotes []{} were added as it allows to json encode. it seems to be accepted as a value
regex = re.compile(r"^[a-zA-Z0-9\s\+\-=\.,_:/@\"\'\[\]\{\}]*$")
min_length = 0
max_length = 256
str,
StringConstraints(
min_length=0,
max_length=256,
Comment on lines +91 to +92
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe use these constants as well here

pattern=r"^[a-zA-Z0-9\s\+\-=\.,_:/@\"\'\[\]\{\}]*$",
),
]


EC2Tags: TypeAlias = dict[AWSTagKey, AWSTagValue]
Expand Down Expand Up @@ -148,8 +161,23 @@ class EC2InstanceBootSpecific(BaseModel):
default=0, description="number of buffer EC2s to keep (defaults to 0)"
)

class Config:
schema_extra: ClassVar[dict[str, Any]] = {
@field_validator("custom_boot_scripts")
@classmethod
def validate_bash_calls(cls, v):
try:
with tempfile.NamedTemporaryFile(mode="wt", delete=True) as temp_file:
temp_file.writelines(v)
temp_file.flush()
# NOTE: this will not capture runtime errors, but at least some syntax errors such as invalid quotes
sh.bash("-n", temp_file.name)
except sh.ErrorReturnCode as exc:
msg = f"Invalid bash call in custom_boot_scripts: {v}, Error: {exc.stderr}"
raise ValueError(msg) from exc

return v

model_config = ConfigDict(
json_schema_extra={
"examples": [
{
# just AMI
Expand Down Expand Up @@ -205,18 +233,4 @@ class Config:
},
]
}

@validator("custom_boot_scripts")
@classmethod
def validate_bash_calls(cls, v):
try:
with tempfile.NamedTemporaryFile(mode="wt", delete=True) as temp_file:
temp_file.writelines(v)
temp_file.flush()
# NOTE: this will not capture runtime errors, but at least some syntax errors such as invalid quotes
sh.bash("-n", temp_file.name)
except sh.ErrorReturnCode as exc:
msg = f"Invalid bash call in custom_boot_scripts: {v}, Error: {exc.stderr}"
raise ValueError(msg) from exc

return v
)
Loading
Loading