From 0ad572ecc70aceb97f8539b1a7f78198089b40c3 Mon Sep 17 00:00:00 2001 From: Patrick Arminio Date: Mon, 10 Nov 2025 16:24:27 +0000 Subject: [PATCH 1/5] =?UTF-8?q?=F0=9F=90=9B=20Fix=20support=20for=20pydant?= =?UTF-8?q?ic=20v1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/test.yml | 29 +++++++++++++++++------------ src/fastapi_cli/config.py | 17 +++++++++++++---- 2 files changed, 30 insertions(+), 16 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 834684c1..b3225532 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -29,14 +29,15 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: - - "3.8" - - "3.9" - - "3.10" - - "3.11" - - "3.12" - - "3.13" - - "3.14" + python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13", "3.14"] + pydantic-version: ["v2"] + include: + - python-version: "3.8" + pydantic-version: "v1" + - python-version: "3.9" + pydantic-version: "v1" + - python-version: "3.10" + pydantic-version: "v1" fail-fast: false steps: - name: Dump GitHub context @@ -63,19 +64,23 @@ jobs: with: limit-access-to-actor: true - name: Install Dependencies - run: uv pip install -r requirements-tests.txt + run: | + uv pip install -r requirements-tests.txt + if [ "${{ matrix.pydantic-version }}" = "v1" ]; then + uv pip install "pydantic<2.0.0" + fi - name: Lint run: bash scripts/lint.sh - run: mkdir coverage - name: Test run: bash scripts/test.sh env: - COVERAGE_FILE: coverage/.coverage.${{ runner.os }}-py${{ matrix.python-version }} - CONTEXT: ${{ runner.os }}-py${{ matrix.python-version }} + COVERAGE_FILE: coverage/.coverage.${{ runner.os }}-py${{ matrix.python-version }}-pydantic-${{ matrix.pydantic-version }} + CONTEXT: ${{ runner.os }}-py${{ matrix.python-version }}-pydantic-${{ matrix.pydantic-version }} - name: Store coverage files uses: actions/upload-artifact@v5 with: - name: coverage-${{ matrix.python-version }} + name: coverage-${{ matrix.python-version }}-pydantic-${{ matrix.pydantic-version }} path: coverage include-hidden-files: true diff --git a/src/fastapi_cli/config.py b/src/fastapi_cli/config.py index 58710c68..dc88b2c2 100644 --- a/src/fastapi_cli/config.py +++ b/src/fastapi_cli/config.py @@ -1,14 +1,18 @@ import logging from pathlib import Path -from typing import Any, Dict, Optional +from typing import Any, Dict, Optional, Union -from pydantic import BaseModel +from pydantic import BaseModel, StrictStr +from pydantic.version import VERSION as PYDANTIC_VERSION logger = logging.getLogger(__name__) +PYDANTIC_VERSION_MINOR_TUPLE = tuple(int(x) for x in PYDANTIC_VERSION.split(".")[:2]) +PYDANTIC_V2 = PYDANTIC_VERSION_MINOR_TUPLE[0] == 2 + class FastAPIConfig(BaseModel): - entrypoint: Optional[str] = None + entrypoint: Optional[StrictStr] = None @classmethod def _read_pyproject_toml(cls) -> Dict[str, Any]: @@ -39,4 +43,9 @@ def resolve(cls, entrypoint: Optional[str] = None) -> "FastAPIConfig": if entrypoint is not None: config["entrypoint"] = entrypoint - return FastAPIConfig.model_validate(config) + # Pydantic v2 uses model_validate, v1 uses parse_obj + # Use getattr to avoid mypy errors with different Pydantic versions + if not PYDANTIC_V2: + return cls.parse_obj(config) # type: ignore[no-any-return, unused-ignore] + + return cls.model_validate(config) # type: ignore[no-any-return, unused-ignore, attr-defined] From 6ade0a6a68a6300e3dddbae32c603209276b0ffe Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 10 Nov 2025 17:46:52 +0000 Subject: [PATCH 2/5] =?UTF-8?q?=F0=9F=8E=A8=20[pre-commit.ci]=20Auto=20for?= =?UTF-8?q?mat=20from=20pre-commit.com=20hooks?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/fastapi_cli/config.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/fastapi_cli/config.py b/src/fastapi_cli/config.py index dc88b2c2..a225b2f7 100644 --- a/src/fastapi_cli/config.py +++ b/src/fastapi_cli/config.py @@ -1,6 +1,6 @@ import logging from pathlib import Path -from typing import Any, Dict, Optional, Union +from typing import Any, Dict, Optional from pydantic import BaseModel, StrictStr from pydantic.version import VERSION as PYDANTIC_VERSION From 2ee19ec5e3617a4dc4d368e7f2c7ba9bf08abdde Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Ram=C3=ADrez?= Date: Mon, 10 Nov 2025 19:50:16 +0100 Subject: [PATCH 3/5] =?UTF-8?q?=F0=9F=91=B7=20Tweak=20tests=20format=20to?= =?UTF-8?q?=20use=20the=20same=20style=20as=20FastAPI=20for=20conditional?= =?UTF-8?q?=20installs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/test.yml | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b3225532..fcf4fedf 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -64,11 +64,10 @@ jobs: with: limit-access-to-actor: true - name: Install Dependencies - run: | - uv pip install -r requirements-tests.txt - if [ "${{ matrix.pydantic-version }}" = "v1" ]; then - uv pip install "pydantic<2.0.0" - fi + run: uv pip install -r requirements-tests.txt + - name: Install Pydantic v1 + if: matrix.pydantic-version == 'v1' + run: uv pip install "pydantic<2.0.0" - name: Lint run: bash scripts/lint.sh - run: mkdir coverage From 5d3719542a726f0908d2326811cf657de878b6cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Ram=C3=ADrez?= Date: Mon, 10 Nov 2025 19:50:46 +0100 Subject: [PATCH 4/5] =?UTF-8?q?=F0=9F=94=A5=20Remove=20old=20comment?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/fastapi_cli/config.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/fastapi_cli/config.py b/src/fastapi_cli/config.py index a225b2f7..f5304bad 100644 --- a/src/fastapi_cli/config.py +++ b/src/fastapi_cli/config.py @@ -44,7 +44,6 @@ def resolve(cls, entrypoint: Optional[str] = None) -> "FastAPIConfig": config["entrypoint"] = entrypoint # Pydantic v2 uses model_validate, v1 uses parse_obj - # Use getattr to avoid mypy errors with different Pydantic versions if not PYDANTIC_V2: return cls.parse_obj(config) # type: ignore[no-any-return, unused-ignore] From 9532eb3754a981546a0dcdff614655a85aa3ce49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Ram=C3=ADrez?= Date: Mon, 10 Nov 2025 19:52:23 +0100 Subject: [PATCH 5/5] =?UTF-8?q?=F0=9F=94=A7=20Use=20same=20previous=20yaml?= =?UTF-8?q?=20style=20lists?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/test.yml | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index fcf4fedf..220c0901 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -29,8 +29,16 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13", "3.14"] - pydantic-version: ["v2"] + python-version: + - "3.8" + - "3.9" + - "3.10" + - "3.11" + - "3.12" + - "3.13" + - "3.14" + pydantic-version: + - "v2" include: - python-version: "3.8" pydantic-version: "v1"