Skip to content

Commit cc8758d

Browse files
authored
➖ Drop support for Pydantic v1 (#139)
1 parent 7337d93 commit cc8758d

10 files changed

Lines changed: 23 additions & 121 deletions

File tree

.github/workflows/test.yml

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,6 @@ jobs:
2626
strategy:
2727
matrix:
2828
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13", "3.14"]
29-
pydantic-version: ["v2"]
30-
include:
31-
- python-version: "3.9"
32-
pydantic-version: "v1"
33-
- python-version: "3.10"
34-
pydantic-version: "v1"
35-
- python-version: "3.11"
36-
pydantic-version: "v1"
37-
- python-version: "3.12"
38-
pydantic-version: "v1"
3929
fail-fast: false
4030
runs-on: ubuntu-latest
4131
env:
@@ -63,9 +53,6 @@ jobs:
6353
limit-access-to-actor: true
6454
- name: Install Dependencies
6555
run: uv sync --locked --all-extras --dev
66-
- name: Install Pydantic v1
67-
if: matrix.pydantic-version == 'v1'
68-
run: uv pip install "pydantic<2.0.0"
6956
- name: Lint
7057
run: uv run --no-sync scripts/lint.sh
7158
- run: mkdir coverage
@@ -77,7 +64,7 @@ jobs:
7764
- name: Store coverage files
7865
uses: actions/upload-artifact@v4
7966
with:
80-
name: coverage-${{ matrix.python-version }}-${{ matrix.pydantic-version }}
67+
name: coverage-${{ matrix.python-version }}
8168
path: coverage
8269
include-hidden-files: true
8370

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ dependencies = [
3434
"rignore >= 0.5.1",
3535
"httpx >= 0.27.0",
3636
"rich-toolkit >= 0.14.5",
37-
"pydantic[email] >= 1.6.1",
37+
"pydantic[email] >= 2.0",
3838
"sentry-sdk >= 2.20.0",
3939
"fastar >= 0.8.0",
4040
]

src/fastapi_cloud_cli/commands/deploy.py

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import rignore
1414
import typer
1515
from httpx import Client
16-
from pydantic import BaseModel, EmailStr, ValidationError
16+
from pydantic import BaseModel, EmailStr, TypeAdapter, ValidationError
1717
from rich.text import Text
1818
from rich_toolkit import RichToolkit
1919
from rich_toolkit.menu import Option
@@ -23,11 +23,6 @@
2323
from fastapi_cloud_cli.utils.apps import AppConfig, get_app_config, write_app_config
2424
from fastapi_cloud_cli.utils.auth import is_logged_in
2525
from fastapi_cloud_cli.utils.cli import get_rich_toolkit, handle_http_errors
26-
from fastapi_cloud_cli.utils.pydantic_compat import (
27-
TypeAdapter,
28-
model_dump,
29-
model_validate,
30-
)
3126

3227
logger = logging.getLogger(__name__)
3328

@@ -108,7 +103,7 @@ def _get_teams() -> list[Team]:
108103

109104
data = response.json()["data"]
110105

111-
return [model_validate(Team, team) for team in data]
106+
return [Team.model_validate(team) for team in data]
112107

113108

114109
class AppResponse(BaseModel):
@@ -125,7 +120,7 @@ def _create_app(team_id: str, app_name: str) -> AppResponse:
125120

126121
response.raise_for_status()
127122

128-
return model_validate(AppResponse, response.json())
123+
return AppResponse.model_validate(response.json())
129124

130125

131126
class DeploymentStatus(str, Enum):
@@ -178,7 +173,7 @@ def _create_deployment(app_id: str) -> CreateDeploymentResponse:
178173
response = client.post(f"/apps/{app_id}/deployments/")
179174
response.raise_for_status()
180175

181-
return model_validate(CreateDeploymentResponse, response.json())
176+
return CreateDeploymentResponse.model_validate(response.json())
182177

183178

184179
class RequestUploadResponse(BaseModel):
@@ -203,7 +198,7 @@ def _upload_deployment(deployment_id: str, archive_path: Path) -> None:
203198
response = fastapi_client.post(f"/deployments/{deployment_id}/upload")
204199
response.raise_for_status()
205200

206-
upload_data = model_validate(RequestUploadResponse, response.json())
201+
upload_data = RequestUploadResponse.model_validate(response.json())
207202
logger.debug("Received upload URL: %s", upload_data.url)
208203

209204
logger.debug("Starting file upload to S3")
@@ -238,7 +233,7 @@ def _get_app(app_slug: str) -> Optional[AppResponse]:
238233

239234
data = response.json()
240235

241-
return model_validate(AppResponse, data)
236+
return AppResponse.model_validate(data)
242237

243238

244239
def _get_apps(team_id: str) -> list[AppResponse]:
@@ -248,7 +243,7 @@ def _get_apps(team_id: str) -> list[AppResponse]:
248243

249244
data = response.json()["data"]
250245

251-
return [model_validate(AppResponse, app) for app in data]
246+
return [AppResponse.model_validate(app) for app in data]
252247

253248

254249
WAITING_MESSAGES = [
@@ -434,7 +429,7 @@ def _send_waitlist_form(
434429
with toolkit.progress("Sending your request...") as progress:
435430
with APIClient() as client:
436431
with handle_http_errors(progress):
437-
response = client.post("/users/waiting-list", json=model_dump(result))
432+
response = client.post("/users/waiting-list", json=result.model_dump())
438433

439434
response.raise_for_status()
440435

@@ -459,7 +454,7 @@ def _waitlist_form(toolkit: RichToolkit) -> None:
459454

460455
toolkit.print_line()
461456

462-
result = model_validate(SignupToWaitingList, {"email": email})
457+
result = SignupToWaitingList.model_validate({"email": email})
463458

464459
if toolkit.confirm(
465460
"Do you want to get access faster by giving us more information?",
@@ -483,8 +478,7 @@ def _waitlist_form(toolkit: RichToolkit) -> None:
483478
result = form.run() # type: ignore
484479

485480
try:
486-
result = model_validate(
487-
SignupToWaitingList,
481+
result = SignupToWaitingList.model_validate(
488482
{
489483
"email": email,
490484
**result, # type: ignore

src/fastapi_cloud_cli/commands/env.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
from fastapi_cloud_cli.utils.auth import is_logged_in
1111
from fastapi_cloud_cli.utils.cli import get_rich_toolkit, handle_http_errors
1212
from fastapi_cloud_cli.utils.env import validate_environment_variable_name
13-
from fastapi_cloud_cli.utils.pydantic_compat import model_validate
1413

1514
logger = logging.getLogger(__name__)
1615

@@ -29,7 +28,7 @@ def _get_environment_variables(app_id: str) -> EnvironmentVariableResponse:
2928
response = client.get(f"/apps/{app_id}/environment-variables/")
3029
response.raise_for_status()
3130

32-
return model_validate(EnvironmentVariableResponse, response.json())
31+
return EnvironmentVariableResponse.model_validate(response.json())
3332

3433

3534
def _delete_environment_variable(app_id: str, name: str) -> bool:

src/fastapi_cloud_cli/commands/login.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
write_auth_config,
1717
)
1818
from fastapi_cloud_cli.utils.cli import get_rich_toolkit, handle_http_errors
19-
from fastapi_cloud_cli.utils.pydantic_compat import model_validate_json
2019

2120
logger = logging.getLogger(__name__)
2221

@@ -44,7 +43,7 @@ def _start_device_authorization(
4443

4544
response.raise_for_status()
4645

47-
return model_validate_json(AuthorizationData, response.text)
46+
return AuthorizationData.model_validate_json(response.text)
4847

4948

5049
def _fetch_access_token(client: httpx.Client, device_code: str, interval: int) -> str:
@@ -74,7 +73,7 @@ def _fetch_access_token(client: httpx.Client, device_code: str, interval: int) -
7473

7574
time.sleep(interval)
7675

77-
response_data = model_validate_json(TokenResponse, response.text)
76+
response_data = TokenResponse.model_validate_json(response.text)
7877

7978
return response_data.access_token
8079

src/fastapi_cloud_cli/utils/api.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,12 @@
1515
)
1616

1717
import httpx
18-
from pydantic import BaseModel, Field, ValidationError
18+
from pydantic import BaseModel, Field, TypeAdapter, ValidationError
1919
from typing_extensions import ParamSpec
2020

2121
from fastapi_cloud_cli import __version__
2222
from fastapi_cloud_cli.config import Settings
2323
from fastapi_cloud_cli.utils.auth import get_auth_token
24-
from fastapi_cloud_cli.utils.pydantic_compat import TypeAdapter
2524

2625
logger = logging.getLogger(__name__)
2726

@@ -49,8 +48,8 @@ class BuildLogLineMessage(BaseModel):
4948

5049

5150
BuildLogLine = Union[BuildLogLineMessage, BuildLogLineGeneric]
52-
BuildLogAdapter = TypeAdapter[BuildLogLine](
53-
Annotated[BuildLogLine, Field(discriminator="type")] # type: ignore
51+
BuildLogAdapter: TypeAdapter[BuildLogLine] = TypeAdapter(
52+
Annotated[BuildLogLine, Field(discriminator="type")]
5453
)
5554

5655

src/fastapi_cloud_cli/utils/apps.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44

55
from pydantic import BaseModel
66

7-
from fastapi_cloud_cli.utils.pydantic_compat import model_dump_json, model_validate_json
8-
97
logger = logging.getLogger("fastapi_cli")
108

119

@@ -23,7 +21,7 @@ def get_app_config(path_to_deploy: Path) -> Optional[AppConfig]:
2321
return None
2422

2523
logger.debug("App config loaded successfully")
26-
return model_validate_json(AppConfig, config_path.read_text(encoding="utf-8"))
24+
return AppConfig.model_validate_json(config_path.read_text(encoding="utf-8"))
2725

2826

2927
README = """
@@ -52,7 +50,7 @@ def write_app_config(path_to_deploy: Path, app_config: AppConfig) -> None:
5250
config_path.parent.mkdir(parents=True, exist_ok=True)
5351

5452
config_path.write_text(
55-
model_dump_json(app_config),
53+
app_config.model_dump_json(),
5654
encoding="utf-8",
5755
)
5856
readme_path.write_text(README, encoding="utf-8")

src/fastapi_cloud_cli/utils/auth.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77

88
from pydantic import BaseModel
99

10-
from fastapi_cloud_cli.utils.pydantic_compat import model_dump_json, model_validate_json
11-
1210
from .config import get_auth_path
1311

1412
logger = logging.getLogger("fastapi_cli")
@@ -22,7 +20,7 @@ def write_auth_config(auth_data: AuthConfig) -> None:
2220
auth_path = get_auth_path()
2321
logger.debug("Writing auth config to: %s", auth_path)
2422

25-
auth_path.write_text(model_dump_json(auth_data), encoding="utf-8")
23+
auth_path.write_text(auth_data.model_dump_json(), encoding="utf-8")
2624
logger.debug("Auth config written successfully")
2725

2826

@@ -46,7 +44,7 @@ def read_auth_config() -> Optional[AuthConfig]:
4644
return None
4745

4846
logger.debug("Auth config loaded successfully")
49-
return model_validate_json(AuthConfig, auth_path.read_text(encoding="utf-8"))
47+
return AuthConfig.model_validate_json(auth_path.read_text(encoding="utf-8"))
5048

5149

5250
def get_auth_token() -> Optional[str]:

src/fastapi_cloud_cli/utils/pydantic_compat.py

Lines changed: 0 additions & 72 deletions
This file was deleted.

uv.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)