Skip to content

Commit

Permalink
fix: correct working with dependencies versions (#1918)
Browse files Browse the repository at this point in the history
* fix: correct working with dependencies versions

* fix: correct FastAPI patch version check
  • Loading branch information
Lancetnik authored Nov 14, 2024
1 parent bd188c7 commit fe0e46b
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 20 deletions.
28 changes: 13 additions & 15 deletions faststream/_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,8 @@
from importlib.metadata import version as get_version
from typing import Any, Callable, Dict, Mapping, Optional, Type, TypeVar, Union

from fast_depends._compat import PYDANTIC_V2 as PYDANTIC_V2
from fast_depends._compat import ( # type: ignore[attr-defined]
PYDANTIC_VERSION as PYDANTIC_VERSION,
)
from pydantic import BaseModel as BaseModel
from pydantic.version import VERSION as PYDANTIC_VERSION

from faststream.types import AnyDict

Expand Down Expand Up @@ -57,23 +54,23 @@ def json_dumps(*a: Any, **kw: Any) -> bytes:

JsonSchemaValue = Mapping[str, Any]

major, minor, *_ = PYDANTIC_VERSION.split(".")
_PYDANTCI_MAJOR, _PYDANTIC_MINOR = int(major), int(minor)

PYDANTIC_V2 = _PYDANTCI_MAJOR >= 2

if PYDANTIC_V2:
if PYDANTIC_VERSION >= "2.4.0":
if _PYDANTIC_MINOR >= 4:
from pydantic.annotated_handlers import (
GetJsonSchemaHandler as GetJsonSchemaHandler,
)
from pydantic_core.core_schema import (
with_info_plain_validator_function as with_info_plain_validator_function,
)
else:
if PYDANTIC_VERSION >= "2.10":
from pydantic.annotated_handlers import (
GetJsonSchemaHandler as GetJsonSchemaHandler,
)
else:
from pydantic._internal._annotated_handlers import ( # type: ignore[no-redef]
GetJsonSchemaHandler as GetJsonSchemaHandler,
)
from pydantic._internal._annotated_handlers import ( # type: ignore[no-redef]
GetJsonSchemaHandler as GetJsonSchemaHandler,
)
from pydantic_core.core_schema import (
general_plain_validator_function as with_info_plain_validator_function,
)
Expand Down Expand Up @@ -155,8 +152,9 @@ def with_info_plain_validator_function( # type: ignore[misc]
return {}


anyio_major = int(get_version("anyio").split(".")[0])
ANYIO_V3 = anyio_major == 3
major, *_ = get_version("anyio").split(".")
_ANYIO_MAJOR = int(major)
ANYIO_V3 = _ANYIO_MAJOR == 3


if ANYIO_V3:
Expand Down
28 changes: 23 additions & 5 deletions faststream/broker/fastapi/_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,29 @@
from fastapi.dependencies.models import Dependant
from fastapi.requests import Request

major, minor, patch, *_ = map(int, FASTAPI_VERSION.split("."))
FASTAPI_V2 = major > 0 or minor > 100
FASTAPI_V106 = major > 0 or minor >= 106
FASTAPI_v102_3 = major > 0 or minor > 112 or (minor == 112 and patch > 2)
FASTAPI_v102_4 = major > 0 or minor > 112 or (minor == 112 and patch > 3)
major, minor, patch, *_ = FASTAPI_VERSION.split(".")

_FASTAPI_MAJOR, _FASTAPI_MINOR = int(major), int(minor)

FASTAPI_V2 = _FASTAPI_MAJOR > 0 or _FASTAPI_MINOR > 100
FASTAPI_V106 = _FASTAPI_MAJOR > 0 or _FASTAPI_MINOR >= 106

try:
_FASTAPI_PATCH = int(patch)
except ValueError:
FASTAPI_v102_3 = True
FASTAPI_v102_4 = True
else:
FASTAPI_v102_3 = (
_FASTAPI_MAJOR > 0
or _FASTAPI_MINOR > 112
or (_FASTAPI_MINOR == 112 and _FASTAPI_PATCH > 2)
)
FASTAPI_v102_4 = (
_FASTAPI_MAJOR > 0
or _FASTAPI_MINOR > 112
or (_FASTAPI_MINOR == 112 and _FASTAPI_PATCH > 3)
)

__all__ = (
"create_response_field",
Expand Down

0 comments on commit fe0e46b

Please sign in to comment.