Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci #1

Closed
wants to merge 3 commits into from
Closed

ci #1

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
6 changes: 6 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version: 2
updates:
- package-ecosystem: github-actions
directory: /
schedule:
interval: weekly
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
strategy:
max-parallel: 3
matrix:
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11']
python-version: ['3.8', '3.9', '3.10', '3.11']

steps:
- uses: actions/checkout@v1
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
strategy:
max-parallel: 3
matrix:
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11']
python-version: ['3.8', '3.9', '3.10', '3.11']

steps:
- uses: actions/checkout@v1
Expand Down
27 changes: 21 additions & 6 deletions fastapi_utils/api_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,16 @@

from functools import partial

from pydantic import BaseConfig, BaseModel
from pydantic import BaseModel
from pydantic import __version__ as pydantic_version

from fastapi_utils.camelcase import snake2camel

if pydantic_version < "2.0":
from pydantic import BaseConfig
else:
from pydantic import ConfigDict


class APIModel(BaseModel):
"""
Expand All @@ -14,14 +20,23 @@ class APIModel(BaseModel):
Any models that inherit from this class will:
* accept fields using snake_case or camelCase keys
* use camelCase keys in the generated OpenAPI spec
* have orm_mode on by default
* have from_attributes on by default
* Because of this, FastAPI will automatically attempt to parse returned orm instances into the model
"""

class Config(BaseConfig):
orm_mode = True
allow_population_by_field_name = True
alias_generator = partial(snake2camel, start_lower=True)
if pydantic_version < "2.0":

class Config(BaseConfig):
orm_mode = True
allow_population_by_field_name = True
alias_generator = partial(snake2camel, start_lower=True)

else:
model_config = ConfigDict(
from_attributes=True,
populate_by_name=True,
alias_generator=partial(snake2camel, start_lower=True),
)


class APIMessage(APIModel):
Expand Down
26 changes: 21 additions & 5 deletions fastapi_utils/api_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,21 @@
from functools import lru_cache
from typing import Any

from pydantic import BaseSettings
from pydantic import __version__ as pydantic_version

if pydantic_version < "2.0":
from pydantic import BaseSettings
else:
try:
from pydantic_settings import BaseSettings, SettingsConfigDict
except ImportError:
raise ImportError(
"You are using pydantic >= 2.0, but you do not have pydantic-settings installed. "
"Please install pydantic-settings to use the APISettings class."
)

class APISettings(BaseSettings):

class APISettings(BaseSettings): # type: ignore[misc,valid-type]
"""
This class enables the configuration of your FastAPI instance through the use of environment variables.

Expand Down Expand Up @@ -53,9 +64,14 @@ def fastapi_kwargs(self) -> dict[str, Any]:
fastapi_kwargs.update({"docs_url": None, "openapi_url": None, "redoc_url": None})
return fastapi_kwargs

class Config:
env_prefix = "api_"
validate_assignment = True
if pydantic_version < "2.0":

class Config:
env_prefix = "api_"
validate_assignment = True

else:
model_config = SettingsConfigDict(env_prefix="api_", validate_assignment=True)


@lru_cache()
Expand Down
5 changes: 2 additions & 3 deletions fastapi_utils/cbv.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@

import inspect
from collections.abc import Callable
from typing import Any, TypeVar, get_type_hints
from typing import Any, ClassVar, TypeVar, get_origin, get_type_hints

from fastapi import APIRouter, Depends
from pydantic.typing import is_classvar
from starlette.routing import Route, WebSocketRoute

T = TypeVar("T")
Expand Down Expand Up @@ -69,7 +68,7 @@ def _init_cbv(cls: type[Any]) -> None:
]
dependency_names: list[str] = []
for name, hint in get_type_hints(cls).items():
if is_classvar(hint):
if get_origin(hint) is ClassVar:
continue
parameter_kwargs = {"default": getattr(cls, name, Ellipsis)}
dependency_names.append(name)
Expand Down
1,723 changes: 854 additions & 869 deletions poetry.lock

Large diffs are not rendered by default.

10 changes: 7 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ classifiers = [
"Intended Audience :: Developers",
"License :: OSI Approved :: MIT License",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
Expand All @@ -37,11 +36,16 @@ classifiers = [
]

[tool.poetry.dependencies]
python = "^3.7"
python = "^3.8"

fastapi = "*"
pydantic = "^1.10,<2.0"
pydantic = ">=1.10,<3.0"
sqlalchemy = "^1.4,<2.0"
# pydantic-settings is a dependency if and only if we use pydantic 2.x, this is not displayable with poetry
pydantic-settings = { version = "^2.0", optional = true }

[tool.poetry.extras]
pydantic2 = ["pydantic-settings"]

[tool.poetry.dev-dependencies]
# Starlette features
Expand Down
Loading