Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Conditional imports to support operating with pydantic>2 installed (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisguidry authored Oct 4, 2023
1 parent 50ad8f8 commit 525c917
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 9 deletions.
7 changes: 6 additions & 1 deletion prefect_aws/client_parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@

from botocore import UNSIGNED
from botocore.client import Config
from pydantic import BaseModel, Field, FilePath, root_validator, validator
from pydantic import VERSION as PYDANTIC_VERSION

if PYDANTIC_VERSION.startswith("2."):
from pydantic.v1 import BaseModel, Field, FilePath, root_validator, validator
else:
from pydantic import BaseModel, Field, FilePath, root_validator, validator


class AwsClientParameters(BaseModel):
Expand Down
7 changes: 6 additions & 1 deletion prefect_aws/credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@
from mypy_boto3_s3 import S3Client
from mypy_boto3_secretsmanager import SecretsManagerClient
from prefect.blocks.abstract import CredentialsBlock
from pydantic import Field, SecretStr
from pydantic import VERSION as PYDANTIC_VERSION

if PYDANTIC_VERSION.startswith("2."):
from pydantic.v1 import Field, SecretStr
else:
from pydantic import Field, SecretStr

from prefect_aws.client_parameters import AwsClientParameters

Expand Down
8 changes: 7 additions & 1 deletion prefect_aws/ecs.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,13 @@
from prefect.utilities.asyncutils import run_sync_in_worker_thread, sync_compatible
from prefect.utilities.dockerutils import get_prefect_image_name
from prefect.utilities.pydantic import JsonPatch
from pydantic import Field, root_validator, validator
from pydantic import VERSION as PYDANTIC_VERSION

if PYDANTIC_VERSION.startswith("2."):
from pydantic.v1 import Field, root_validator, validator
else:
from pydantic import Field, root_validator, validator

from slugify import slugify
from typing_extensions import Literal, Self

Expand Down
7 changes: 6 additions & 1 deletion prefect_aws/s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@
from prefect.filesystems import WritableDeploymentStorage, WritableFileSystem
from prefect.utilities.asyncutils import run_sync_in_worker_thread, sync_compatible
from prefect.utilities.filesystem import filter_files
from pydantic import Field
from pydantic import VERSION as PYDANTIC_VERSION

if PYDANTIC_VERSION.startswith("2."):
from pydantic.v1 import Field
else:
from pydantic import Field

from prefect_aws import AwsCredentials, MinIOCredentials
from prefect_aws.client_parameters import AwsClientParameters
Expand Down
7 changes: 6 additions & 1 deletion prefect_aws/secrets_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@
from prefect import get_run_logger, task
from prefect.blocks.abstract import SecretBlock
from prefect.utilities.asyncutils import run_sync_in_worker_thread, sync_compatible
from pydantic import Field
from pydantic import VERSION as PYDANTIC_VERSION

if PYDANTIC_VERSION.startswith("2."):
from pydantic.v1 import Field
else:
from pydantic import Field

from prefect_aws import AwsCredentials

Expand Down
8 changes: 7 additions & 1 deletion prefect_aws/workers/ecs_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,13 @@
BaseWorker,
BaseWorkerResult,
)
from pydantic import Field, root_validator
from pydantic import VERSION as PYDANTIC_VERSION

if PYDANTIC_VERSION.startswith("2."):
from pydantic.v1 import Field, root_validator
else:
from pydantic import Field, root_validator

from slugify import slugify
from tenacity import retry, stop_after_attempt, wait_fixed, wait_random
from typing_extensions import Literal
Expand Down
4 changes: 3 additions & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ mkdocs-gen-files
mkdocs-material
mkdocstrings-python-legacy
mock; python_version < '3.8'
moto >= 3.1.16
# moto 4.2.5 broke something fairly deep in our test suite
# https://github.com/PrefectHQ/prefect-aws/issues/318
moto >= 3.1.16, < 4.2.5
mypy
pillow
pre-commit
Expand Down
7 changes: 6 additions & 1 deletion tests/test_ecs.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@
from prefect.server.schemas.core import Deployment, Flow, FlowRun
from prefect.utilities.asyncutils import run_sync_in_worker_thread
from prefect.utilities.dockerutils import get_prefect_image_name
from pydantic import ValidationError
from pydantic import VERSION as PYDANTIC_VERSION

if PYDANTIC_VERSION.startswith("2."):
from pydantic.v1 import ValidationError
else:
from pydantic import ValidationError

from prefect_aws.ecs import (
ECS_DEFAULT_CPU,
Expand Down
8 changes: 7 additions & 1 deletion tests/workers/test_ecs_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,13 @@
from moto.ec2.utils import generate_instance_identity_document
from prefect.server.schemas.core import FlowRun
from prefect.utilities.asyncutils import run_sync_in_worker_thread
from pydantic import ValidationError
from pydantic import VERSION as PYDANTIC_VERSION

if PYDANTIC_VERSION.startswith("2."):
from pydantic.v1 import ValidationError
else:
from pydantic import ValidationError

from tenacity import RetryError

from prefect_aws.workers.ecs_worker import (
Expand Down

0 comments on commit 525c917

Please sign in to comment.