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 pydantic>2 (#215)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisguidry authored Oct 4, 2023
1 parent 78fbac0 commit aa58459
Show file tree
Hide file tree
Showing 11 changed files with 72 additions and 11 deletions.
8 changes: 7 additions & 1 deletion prefect_gcp/aiplatform.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,13 @@
from prefect.exceptions import InfrastructureNotFound
from prefect.infrastructure import Infrastructure, InfrastructureResult
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 slugify import slugify
from typing_extensions import Literal

Expand Down
7 changes: 6 additions & 1 deletion prefect_gcp/bigquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@
from prefect.blocks.abstract import DatabaseBlock
from prefect.utilities.asyncutils import run_sync_in_worker_thread, sync_compatible
from prefect.utilities.hashing import hash_objects
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_gcp.credentials import GcpCredentials

Expand Down
8 changes: 7 additions & 1 deletion prefect_gcp/cloud_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,13 @@
from prefect.exceptions import InfrastructureNotFound
from prefect.infrastructure.base import Infrastructure, InfrastructureResult
from prefect.utilities.asyncutils import run_sync_in_worker_thread, sync_compatible
from pydantic import BaseModel, Field, root_validator, validator
from pydantic import VERSION as PYDANTIC_VERSION

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

from typing_extensions import Literal

from prefect_gcp.credentials import GcpCredentials
Expand Down
7 changes: 6 additions & 1 deletion prefect_gcp/cloud_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@
from prefect.logging import disable_run_logger
from prefect.utilities.asyncutils import run_sync_in_worker_thread, sync_compatible
from prefect.utilities.filesystem import filter_files
from pydantic import Field, validator
from pydantic import VERSION as PYDANTIC_VERSION

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

# cannot be type_checking only or else `fields = cls.schema()` raises
# TypeError: issubclass() arg 1 must be a class
Expand Down
7 changes: 6 additions & 1 deletion prefect_gcp/credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@
from prefect.blocks.abstract import CredentialsBlock
from prefect.blocks.fields import SecretDict
from prefect.utilities.asyncutils import run_sync_in_worker_thread, sync_compatible
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

try:
from google.cloud.bigquery import Client as BigQueryClient
Expand Down
7 changes: 6 additions & 1 deletion prefect_gcp/secret_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,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_gcp.credentials import GcpCredentials

Expand Down
7 changes: 6 additions & 1 deletion prefect_gcp/workers/cloud_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,12 @@
BaseWorker,
BaseWorkerResult,
)
from pydantic import Field, validator
from pydantic import VERSION as PYDANTIC_VERSION

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

from prefect_gcp.cloud_run import Execution, Job
from prefect_gcp.credentials import GcpCredentials
Expand Down
8 changes: 7 additions & 1 deletion prefect_gcp/workers/vertex.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,13 @@
BaseWorker,
BaseWorkerResult,
)
from pydantic import Field, validator
from pydantic import VERSION as PYDANTIC_VERSION

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

from slugify import slugify

from prefect_gcp.credentials import GcpCredentials
Expand Down
8 changes: 7 additions & 1 deletion tests/test_cloud_run.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
from unittest.mock import Mock

import anyio
import pydantic
from pydantic import VERSION as PYDANTIC_VERSION

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

import pytest
from googleapiclient.errors import HttpError
from prefect.exceptions import InfrastructureNotFound
Expand Down
8 changes: 7 additions & 1 deletion tests/test_cloud_run_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@
from unittest.mock import Mock

import anyio
import pydantic
from pydantic import VERSION as PYDANTIC_VERSION

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

import pytest
from googleapiclient.errors import HttpError
from jsonschema.exceptions import ValidationError
Expand Down
8 changes: 7 additions & 1 deletion tests/test_vertex_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@
from unittest.mock import MagicMock

import anyio
import pydantic
from pydantic import VERSION as PYDANTIC_VERSION

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

import pytest
from google.cloud.aiplatform_v1.types.job_service import CancelCustomJobRequest
from google.cloud.aiplatform_v1.types.job_state import JobState
Expand Down

0 comments on commit aa58459

Please sign in to comment.