diff --git a/lambdas/pkgpush/requirements.txt b/lambdas/pkgpush/requirements.txt index adc370dea09..861868c66ce 100644 --- a/lambdas/pkgpush/requirements.txt +++ b/lambdas/pkgpush/requirements.txt @@ -4,6 +4,8 @@ # # pip-compile # +annotated-types==0.7.0 + # via pydantic attrs==23.2.0 # via # jsonschema @@ -53,15 +55,17 @@ pkgutil-resolve-name==1.3.10 # via jsonschema platformdirs==4.2.0 # via quilt3 -pydantic==1.10.14 +pydantic==2.8.2 # via # quilt-shared # t4_lambda_pkgpush (setup.py) +pydantic-core==2.20.1 + # via pydantic python-dateutil==2.8.2 # via botocore pyyaml==6.0.1 # via quilt3 -quilt-shared[boto,pydantic,quilt] @ git+https://github.com/quiltdata/quilt@7c6edd14fbe8a26613bc26b1bbdc0b956132ef8c#subdirectory=py-shared +quilt-shared[boto,pydantic,quilt] @ git+https://github.com/quiltdata/quilt@b56fe52de4590242f998a23401017b3014411306#subdirectory=py-shared # via t4_lambda_pkgpush (setup.py) quilt3 @ git+https://github.com/quiltdata/quilt@5c2b79128fe4d5d1e6093ff6a7d11d09d3315843#subdirectory=api/python # via @@ -102,11 +106,13 @@ types-s3transfer==0.10.0 # via boto3-stubs typing-extensions==4.9.0 # via + # annotated-types # boto3-stubs # botocore-stubs # mypy-boto3-s3 # mypy-boto3-sts # pydantic + # pydantic-core # quilt-shared # types-aiobotocore # types-aiobotocore-s3 diff --git a/lambdas/pkgpush/setup.py b/lambdas/pkgpush/setup.py index 602dc32791e..21157f0d5e2 100644 --- a/lambdas/pkgpush/setup.py +++ b/lambdas/pkgpush/setup.py @@ -7,7 +7,7 @@ package_dir={"": "src"}, install_requires=[ "boto3 ~= 1.28", - "pydantic ~= 1.10", + "pydantic ~= 2.8", ( "quilt3 @ git+https://github.com/quiltdata/quilt@" "5c2b79128fe4d5d1e6093ff6a7d11d09d3315843" @@ -15,7 +15,7 @@ ), ( "quilt_shared[pydantic,boto,quilt] @ git+https://github.com/quiltdata/quilt@" - "7c6edd14fbe8a26613bc26b1bbdc0b956132ef8c" + "b56fe52de4590242f998a23401017b3014411306" "#subdirectory=py-shared" ), ], diff --git a/lambdas/pkgpush/tests/test_hash_calc.py b/lambdas/pkgpush/tests/test_hash_calc.py index b251dfc0957..53eab48a2c2 100644 --- a/lambdas/pkgpush/tests/test_hash_calc.py +++ b/lambdas/pkgpush/tests/test_hash_calc.py @@ -126,14 +126,15 @@ def test_invoke_hash_lambda(lambda_stub: Stubber): "key": pk.path, "version": pk.version_id, }, - } + }, + separators=(",", ":"), ), }, ) assert ( t4_lambda_pkgpush.invoke_hash_lambda(pk, CREDENTIALS, SCRATCH_BUCKETS) - == checksum + == Checksum(**checksum) ) @@ -164,7 +165,8 @@ def test_invoke_hash_lambda_error(lambda_stub: Stubber): "key": pk.path, "version": pk.version_id, }, - } + }, + separators=(",", ":"), ), }, ) diff --git a/lambdas/s3hash/requirements.txt b/lambdas/s3hash/requirements.txt index ab3d0b83b01..1b03475bb6d 100644 --- a/lambdas/s3hash/requirements.txt +++ b/lambdas/s3hash/requirements.txt @@ -12,6 +12,8 @@ aioitertools==0.11.0 # via aiobotocore aiosignal==1.3.1 # via aiohttp +annotated-types==0.7.0 + # via pydantic async-timeout==4.0.3 # via aiohttp attrs==23.2.0 @@ -75,15 +77,17 @@ pkgutil-resolve-name==1.3.10 # via jsonschema platformdirs==4.2.0 # via quilt3 -pydantic==1.10.14 +pydantic==2.8.2 # via # quilt-shared # t4_lambda_s3hash (setup.py) +pydantic-core==2.20.1 + # via pydantic python-dateutil==2.8.2 # via botocore pyyaml==6.0.1 # via quilt3 -quilt-shared[boto,pydantic,quilt] @ git+https://github.com/quiltdata/quilt@7c6edd14fbe8a26613bc26b1bbdc0b956132ef8c#subdirectory=py-shared +quilt-shared[boto,pydantic,quilt] @ git+https://github.com/quiltdata/quilt@b56fe52de4590242f998a23401017b3014411306#subdirectory=py-shared # via t4_lambda_s3hash (setup.py) quilt3==5.4.0 # via quilt-shared @@ -125,11 +129,13 @@ types-s3transfer==0.10.0 typing-extensions==4.9.0 # via # aioitertools + # annotated-types # boto3-stubs # botocore-stubs # mypy-boto3-s3 # mypy-boto3-sts # pydantic + # pydantic-core # quilt-shared # types-aiobotocore # types-aiobotocore-s3 diff --git a/lambdas/s3hash/setup.py b/lambdas/s3hash/setup.py index 93d866c4d11..4c668218e88 100644 --- a/lambdas/s3hash/setup.py +++ b/lambdas/s3hash/setup.py @@ -8,11 +8,11 @@ install_requires=[ "aiobotocore ~= 2.11", "botocore ~= 1.31", - "pydantic ~= 1.10", + "pydantic ~= 2.8", "types-aiobotocore[s3] ~= 2.11", ( "quilt_shared[pydantic,boto,quilt] @ git+https://github.com/quiltdata/quilt@" - "7c6edd14fbe8a26613bc26b1bbdc0b956132ef8c" + "b56fe52de4590242f998a23401017b3014411306" "#subdirectory=py-shared" ), ], diff --git a/lambdas/s3hash/src/t4_lambda_s3hash/__init__.py b/lambdas/s3hash/src/t4_lambda_s3hash/__init__.py index 7711564fb7b..70127560dd0 100644 --- a/lambdas/s3hash/src/t4_lambda_s3hash/__init__.py +++ b/lambdas/s3hash/src/t4_lambda_s3hash/__init__.py @@ -76,7 +76,7 @@ def sha256_chunked(cls, value: bytes): def for_parts(cls, checksums: T.Sequence[bytes]): return cls.sha256_chunked(hash_parts(checksums)) - _EMPTY_HASH = hashlib.sha256().digest() + _EMPTY_HASH: T.ClassVar[bytes] = hashlib.sha256().digest() @classmethod def empty(cls): diff --git a/py-shared/pyproject.toml b/py-shared/pyproject.toml index 1dfb1c48191..86a8247bf68 100644 --- a/py-shared/pyproject.toml +++ b/py-shared/pyproject.toml @@ -12,7 +12,7 @@ dependencies = [ [project.optional-dependencies] pydantic = [ - "pydantic ~= 1.10", + "pydantic ~= 2.8", "typing-extensions ~= 4.9", ] boto = [ diff --git a/py-shared/src/quilt_shared/lambdas_large_request_handler.py b/py-shared/src/quilt_shared/lambdas_large_request_handler.py index 1b40920a472..0a1aba75e47 100644 --- a/py-shared/src/quilt_shared/lambdas_large_request_handler.py +++ b/py-shared/src/quilt_shared/lambdas_large_request_handler.py @@ -6,6 +6,7 @@ import typing as T import pydantic +import typing_extensions as TX from . import const @@ -15,10 +16,7 @@ from mypy_boto3_s3 import S3Client -class VersionId(pydantic.ConstrainedStr): - strip_whitespace = True - min_length = 1 - max_length = 1024 +VersionId = TX.Annotated[str, pydantic.StringConstraints(strip_whitespace=True, min_length=1, max_length=1024)] class RequestTooLarge(Exception): diff --git a/py-shared/src/quilt_shared/pkgpush.py b/py-shared/src/quilt_shared/pkgpush.py index 7a0a106f59c..23e1948ed69 100644 --- a/py-shared/src/quilt_shared/pkgpush.py +++ b/py-shared/src/quilt_shared/pkgpush.py @@ -4,6 +4,7 @@ import typing as T import pydantic +import typing_extensions as TX from .aws import AWSCredentials from .types import NonEmptyStr @@ -14,12 +15,16 @@ from quilt3.util import PhysicalKey -class TopHash(pydantic.ConstrainedStr): - min_length = 64 - max_length = 64 - regex = r"^[0-9a-f]+$" - strip_whitespace = True - to_lower = True +TopHash = TX.Annotated[ + str, + pydantic.StringConstraints( + min_length=64, + max_length=64, + pattern=r"^[0-9a-f]+$", + strip_whitespace=True, + to_lower=True, + ), +] class S3ObjectSource(pydantic.BaseModel): diff --git a/py-shared/src/quilt_shared/types.py b/py-shared/src/quilt_shared/types.py index 3c2f54231a3..9f55ed66036 100644 --- a/py-shared/src/quilt_shared/types.py +++ b/py-shared/src/quilt_shared/types.py @@ -4,10 +4,7 @@ import pydantic import typing_extensions as TX - -class NonEmptyStr(pydantic.ConstrainedStr): - min_length = 1 - strip_whitespace = True +NonEmptyStr = TX.Annotated[str, pydantic.StringConstraints(min_length=1, strip_whitespace=True)] ConsParams = TX.ParamSpec("ConsParams")