Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@ jobs:
- "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
Expand Down Expand Up @@ -64,18 +73,21 @@ jobs:
limit-access-to-actor: true
- name: Install Dependencies
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
- 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

Expand Down
14 changes: 11 additions & 3 deletions src/fastapi_cli/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@
from pathlib import Path
from typing import Any, Dict, Optional

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]:
Expand Down Expand Up @@ -39,4 +43,8 @@ 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
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]