cadwyn 5.1.1__py3-none-any.whl → 5.1.2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of cadwyn might be problematic. Click here for more details.

cadwyn/__init__.py CHANGED
@@ -2,6 +2,7 @@ import importlib.metadata
2
2
 
3
3
  from .applications import Cadwyn
4
4
  from .changelogs import hidden
5
+ from .dependencies import current_dependency_solver
5
6
  from .route_generation import VersionedAPIRouter, generate_versioned_routers
6
7
  from .schema_generation import generate_versioned_models, migrate_response_body
7
8
  from .structure import (
@@ -32,6 +33,7 @@ __all__ = [
32
33
  "VersionedAPIRouter",
33
34
  "convert_request_to_next_version_for",
34
35
  "convert_response_to_previous_version_for",
36
+ "current_dependency_solver",
35
37
  "endpoint",
36
38
  "enum",
37
39
  "generate_versioned_models",
cadwyn/dependencies.py ADDED
@@ -0,0 +1,5 @@
1
+ from cadwyn.structure.versions import _CURRENT_DEPENDENCY_SOLVER_OPTIONS, _CURRENT_DEPENDENCY_SOLVER_VAR
2
+
3
+
4
+ async def current_dependency_solver() -> _CURRENT_DEPENDENCY_SOLVER_OPTIONS:
5
+ return _CURRENT_DEPENDENCY_SOLVER_VAR.get("fastapi")
@@ -20,6 +20,7 @@ import pydantic
20
20
  import pydantic._internal._decorators
21
21
  import typing_extensions
22
22
  from fastapi import Response
23
+ from fastapi.dependencies.utils import is_async_gen_callable, is_coroutine_callable, is_gen_callable
23
24
  from fastapi.routing import APIRoute
24
25
  from pydantic import BaseModel, Field, RootModel
25
26
  from pydantic._internal import _decorators
@@ -77,6 +78,7 @@ from cadwyn.structure.versions import _CADWYN_REQUEST_PARAM_NAME, _CADWYN_RESPON
77
78
  if TYPE_CHECKING:
78
79
  from cadwyn.structure.versions import HeadVersion, Version, VersionBundle
79
80
 
81
+
80
82
  if sys.version_info >= (3, 10):
81
83
  from typing import _BaseGenericAlias # pyright: ignore[reportAttributeAccessIssue]
82
84
  else:
@@ -486,6 +488,7 @@ class _CallableWrapper:
486
488
  self._original_callable = original_callable
487
489
  if not is_regular_function(original_callable):
488
490
  original_callable = original_callable.__call__
491
+
489
492
  functools.update_wrapper(self, original_callable)
490
493
 
491
494
  @property
@@ -510,6 +513,17 @@ class _AsyncCallableWrapper(_CallableWrapper):
510
513
  return await self._original_callable(*args, **kwargs)
511
514
 
512
515
 
516
+ class _GeneratorCallableWrapper(_CallableWrapper):
517
+ def __call__(self, *args: Any, **kwargs: Any):
518
+ yield from self._original_callable(*args, **kwargs)
519
+
520
+
521
+ class _AsyncGeneratorCallableWrapper(_CallableWrapper):
522
+ async def __call__(self, *args: Any, **kwargs: Any):
523
+ async for value in self._original_callable(*args, **kwargs):
524
+ yield value
525
+
526
+
513
527
  @final
514
528
  class _AnnotationTransformer:
515
529
  def __init__(self, generator: "SchemaGenerator") -> None:
@@ -690,8 +704,12 @@ class _AnnotationTransformer:
690
704
  actual_call = call.__call__
691
705
  else:
692
706
  actual_call = call
693
- if inspect.iscoroutinefunction(actual_call):
707
+ if is_async_gen_callable(actual_call):
708
+ return _AsyncGeneratorCallableWrapper(call)
709
+ elif is_coroutine_callable(actual_call):
694
710
  return _AsyncCallableWrapper(call)
711
+ elif is_gen_callable(actual_call):
712
+ return _GeneratorCallableWrapper(call)
695
713
  else:
696
714
  return _CallableWrapper(call)
697
715
 
@@ -23,7 +23,7 @@ from fastapi.routing import APIRoute, _prepare_response_content
23
23
  from pydantic import BaseModel
24
24
  from pydantic_core import PydanticUndefined
25
25
  from starlette._utils import is_async_callable
26
- from typing_extensions import Any, ParamSpec, TypeAlias, TypeVar, assert_never, deprecated, get_args
26
+ from typing_extensions import Any, Literal, ParamSpec, TypeAlias, TypeVar, assert_never, deprecated, get_args
27
27
 
28
28
  from cadwyn._utils import classproperty
29
29
  from cadwyn.exceptions import (
@@ -51,6 +51,11 @@ _CADWYN_REQUEST_PARAM_NAME = "cadwyn_request_param"
51
51
  _CADWYN_RESPONSE_PARAM_NAME = "cadwyn_response_param"
52
52
  _P = ParamSpec("_P")
53
53
  _R = TypeVar("_R")
54
+ _CURRENT_DEPENDENCY_SOLVER_OPTIONS = Literal["cadwyn", "fastapi"]
55
+ _CURRENT_DEPENDENCY_SOLVER_VAR: ContextVar[_CURRENT_DEPENDENCY_SOLVER_OPTIONS] = ContextVar(
56
+ "cadwyn_dependencies_dry_run"
57
+ )
58
+
54
59
  PossibleInstructions: TypeAlias = Union[
55
60
  AlterSchemaSubInstruction, AlterEndpointSubInstruction, AlterEnumSubInstruction, SchemaHadInstruction, staticmethod
56
61
  ]
@@ -276,6 +281,7 @@ class VersionBundle:
276
281
 
277
282
  if api_version_var is None:
278
283
  api_version_var = ContextVar("cadwyn_api_version")
284
+
279
285
  self.version_values = tuple(version.value for version in self.versions)
280
286
  self.reversed_version_values = tuple(reversed(self.version_values))
281
287
  self.api_version_var = api_version_var
@@ -379,6 +385,8 @@ class VersionBundle:
379
385
  instruction(request_info)
380
386
  request.scope["headers"] = tuple((key.encode(), value.encode()) for key, value in request_info.headers.items())
381
387
  del request._headers
388
+ # This gives us the ability to tell the user whether cadwyn is running its dependencies or FastAPI
389
+ _CURRENT_DEPENDENCY_SOLVER_VAR.set("cadwyn")
382
390
  # Remember this: if len(body_params) == 1, then route.body_schema == route.dependant.body_params[0]
383
391
  result = await solve_dependencies(
384
392
  request=request,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: cadwyn
3
- Version: 5.1.1
3
+ Version: 5.1.2
4
4
  Summary: Production-ready community-driven modern Stripe-like API versioning in FastAPI
5
5
  Project-URL: Source code, https://github.com/zmievsa/cadwyn
6
6
  Project-URL: Documentation, https://docs.cadwyn.dev
@@ -1,4 +1,4 @@
1
- cadwyn/__init__.py,sha256=gWsp-oNP5LhBqWF_rsrv6sEYP9KchTu8xhxAR8uaPm0,1035
1
+ cadwyn/__init__.py,sha256=uXmQDTDNA5BeRlLFn0cmIo6ohXvEApg2FSl2sFb8frw,1120
2
2
  cadwyn/__main__.py,sha256=fGoKJPNVueqqXW4rqwmRUBBMoDGeLEyATdT-rel5Pvs,2449
3
3
  cadwyn/_asts.py,sha256=QvqZmDdwH8U-Ocpj9vYR6MRrIANF8ugk9oZgAo76qLs,5223
4
4
  cadwyn/_importer.py,sha256=QV6HqODCG9K2oL4Vc15fAqL2-plMvUWw_cgaj4Ln4C8,1075
@@ -6,12 +6,13 @@ cadwyn/_render.py,sha256=7jb32Cnbf6xJicYBGRuhGz4U5LUzo8InZbf-gENgnEw,5537
6
6
  cadwyn/_utils.py,sha256=q_mTtMKTNTDzqCza67XST-jaPSfuTgnFLmOe0dlGeYY,2295
7
7
  cadwyn/applications.py,sha256=YyESoMwQMq9jxqai6lNrsL0BAKxjTKW5lm3Se_U81j4,20391
8
8
  cadwyn/changelogs.py,sha256=aBTlsZ8PQpw9t4sSyezNTYDs6CMPtzIGulgAHA1ELPs,19622
9
+ cadwyn/dependencies.py,sha256=9JihGg7MPbP0oBFRWebvIzhh6B-oYqd1EYNjB-OZqpw,241
9
10
  cadwyn/exceptions.py,sha256=gLCikeUPeLJwVjM8_DoSTIFHwmNI7n7vw1atpgHvbMU,1803
10
11
  cadwyn/middleware.py,sha256=jtcysj66Fck_3EteK0zLJCOTMms3g6avi3U8lV-roQI,4316
11
12
  cadwyn/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
12
13
  cadwyn/route_generation.py,sha256=e7mnVqtvTx1Oh_khmrM0dAowhVUOO1K4vaVVEGgXgrY,25230
13
14
  cadwyn/routing.py,sha256=EkV38cDQFAtR1M_fGWeq81lYaSPuDK4Pr8fjTTJVZvY,6912
14
- cadwyn/schema_generation.py,sha256=cKDIb1017JFrHNYla6CjUKC6u2rGg7Sw86paXRkh8Sk,45445
15
+ cadwyn/schema_generation.py,sha256=QrOH8WKUbaQs6ztXkHf1hGb6VLEJOS794bYx4G9lx8k,46113
15
16
  cadwyn/static/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
16
17
  cadwyn/static/docs.html,sha256=WNm5ANJVy51TcIUFOaqKf1Z8eF86CC85TTHPxACtkzw,3455
17
18
  cadwyn/structure/__init__.py,sha256=Wgvjdq3vfl9Yhe-BkcFGAMi_Co11YOfTmJQqgF5Gzx4,655
@@ -20,9 +21,9 @@ cadwyn/structure/data.py,sha256=NWURVnP_84VI2ugp9ppo0Ofyve3pVYjymF9K82Jh-SA,7791
20
21
  cadwyn/structure/endpoints.py,sha256=zUgzglNhBPnmWdJ03A8pFT4zPs_lj8nQ7c7Uo2d-ejU,6246
21
22
  cadwyn/structure/enums.py,sha256=4FCc9aniLE3VuWAVIacrNP_FWxTIUm9JkeeHA_zZdwQ,1254
22
23
  cadwyn/structure/schemas.py,sha256=80AUbko1cksXh7qPBmnknDFLK52xr4kw9HfHeXqcw1I,10813
23
- cadwyn/structure/versions.py,sha256=9ihqt27upAOWXCGYou2rCJ7ZqgxjJshKOFpx2LuLpBE,33905
24
- cadwyn-5.1.1.dist-info/METADATA,sha256=2FaGe5yf2bOMW3MizNMNWB3h2k79b-Zl8UeK_TkPYSo,4562
25
- cadwyn-5.1.1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
26
- cadwyn-5.1.1.dist-info/entry_points.txt,sha256=mGX8wl-Xfhpr5M93SUmkykaqinUaYAvW9rtDSX54gx0,47
27
- cadwyn-5.1.1.dist-info/licenses/LICENSE,sha256=KeCWewiDQYpmSnzF-p_0YpoWiyDcUPaCuG8OWQs4ig4,1072
28
- cadwyn-5.1.1.dist-info/RECORD,,
24
+ cadwyn/structure/versions.py,sha256=PrWA2m-81b7LuYqrmaaEr-LhQ54nXz7sSe_-WKb-9g0,34271
25
+ cadwyn-5.1.2.dist-info/METADATA,sha256=MXBoDEfZl0sej1hR4F8VsiJ5RP9wzf81iFFSLmNbWkM,4562
26
+ cadwyn-5.1.2.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
27
+ cadwyn-5.1.2.dist-info/entry_points.txt,sha256=mGX8wl-Xfhpr5M93SUmkykaqinUaYAvW9rtDSX54gx0,47
28
+ cadwyn-5.1.2.dist-info/licenses/LICENSE,sha256=KeCWewiDQYpmSnzF-p_0YpoWiyDcUPaCuG8OWQs4ig4,1072
29
+ cadwyn-5.1.2.dist-info/RECORD,,
File without changes