cadwyn 3.6.5__tar.gz → 3.7.0__tar.gz

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.

Files changed (34) hide show
  1. {cadwyn-3.6.5 → cadwyn-3.7.0}/PKG-INFO +1 -1
  2. {cadwyn-3.6.5 → cadwyn-3.7.0}/cadwyn/__main__.py +43 -2
  3. {cadwyn-3.6.5 → cadwyn-3.7.0}/cadwyn/codegen/_main.py +3 -0
  4. {cadwyn-3.6.5 → cadwyn-3.7.0}/cadwyn/routing.py +7 -3
  5. {cadwyn-3.6.5 → cadwyn-3.7.0}/pyproject.toml +1 -1
  6. {cadwyn-3.6.5 → cadwyn-3.7.0}/LICENSE +0 -0
  7. {cadwyn-3.6.5 → cadwyn-3.7.0}/README.md +0 -0
  8. {cadwyn-3.6.5 → cadwyn-3.7.0}/cadwyn/__init__.py +0 -0
  9. {cadwyn-3.6.5 → cadwyn-3.7.0}/cadwyn/_asts.py +0 -0
  10. {cadwyn-3.6.5 → cadwyn-3.7.0}/cadwyn/_compat.py +0 -0
  11. {cadwyn-3.6.5 → cadwyn-3.7.0}/cadwyn/_package_utils.py +0 -0
  12. {cadwyn-3.6.5 → cadwyn-3.7.0}/cadwyn/_utils.py +0 -0
  13. {cadwyn-3.6.5 → cadwyn-3.7.0}/cadwyn/applications.py +0 -0
  14. {cadwyn-3.6.5 → cadwyn-3.7.0}/cadwyn/codegen/README.md +0 -0
  15. {cadwyn-3.6.5 → cadwyn-3.7.0}/cadwyn/codegen/__init__.py +0 -0
  16. {cadwyn-3.6.5 → cadwyn-3.7.0}/cadwyn/codegen/_common.py +0 -0
  17. {cadwyn-3.6.5 → cadwyn-3.7.0}/cadwyn/codegen/_plugins/__init__.py +0 -0
  18. {cadwyn-3.6.5 → cadwyn-3.7.0}/cadwyn/codegen/_plugins/class_migrations.py +0 -0
  19. {cadwyn-3.6.5 → cadwyn-3.7.0}/cadwyn/codegen/_plugins/class_rebuilding.py +0 -0
  20. {cadwyn-3.6.5 → cadwyn-3.7.0}/cadwyn/codegen/_plugins/class_renaming.py +0 -0
  21. {cadwyn-3.6.5 → cadwyn-3.7.0}/cadwyn/codegen/_plugins/import_auto_adding.py +0 -0
  22. {cadwyn-3.6.5 → cadwyn-3.7.0}/cadwyn/codegen/_plugins/latest_version_aliasing.py +0 -0
  23. {cadwyn-3.6.5 → cadwyn-3.7.0}/cadwyn/codegen/_plugins/module_migrations.py +0 -0
  24. {cadwyn-3.6.5 → cadwyn-3.7.0}/cadwyn/exceptions.py +0 -0
  25. {cadwyn-3.6.5 → cadwyn-3.7.0}/cadwyn/main.py +0 -0
  26. {cadwyn-3.6.5 → cadwyn-3.7.0}/cadwyn/py.typed +0 -0
  27. {cadwyn-3.6.5 → cadwyn-3.7.0}/cadwyn/structure/__init__.py +0 -0
  28. {cadwyn-3.6.5 → cadwyn-3.7.0}/cadwyn/structure/common.py +0 -0
  29. {cadwyn-3.6.5 → cadwyn-3.7.0}/cadwyn/structure/data.py +0 -0
  30. {cadwyn-3.6.5 → cadwyn-3.7.0}/cadwyn/structure/endpoints.py +0 -0
  31. {cadwyn-3.6.5 → cadwyn-3.7.0}/cadwyn/structure/enums.py +0 -0
  32. {cadwyn-3.6.5 → cadwyn-3.7.0}/cadwyn/structure/modules.py +0 -0
  33. {cadwyn-3.6.5 → cadwyn-3.7.0}/cadwyn/structure/schemas.py +0 -0
  34. {cadwyn-3.6.5 → cadwyn-3.7.0}/cadwyn/structure/versions.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: cadwyn
3
- Version: 3.6.5
3
+ Version: 3.7.0
4
4
  Summary: Production-ready community-driven modern Stripe-like API versioning in FastAPI
5
5
  Home-page: https://github.com/zmievsa/cadwyn
6
6
  License: MIT
@@ -1,10 +1,12 @@
1
1
  import importlib
2
2
  import sys
3
+ import warnings
3
4
  from pathlib import Path
4
5
  from typing import Any
5
6
 
6
7
  import typer
7
8
 
9
+ from cadwyn.exceptions import CadwynError
8
10
  from cadwyn.structure.versions import VersionBundle
9
11
 
10
12
  app = typer.Typer(
@@ -22,8 +24,8 @@ def version_callback(value: bool):
22
24
  raise typer.Exit
23
25
 
24
26
 
25
- @app.command(name="generate-code-for-versioned-packages")
26
- def generate_versioned_packages(
27
+ @app.command(name="generate-code-for-versioned-packages", hidden=True)
28
+ def deprecated_generate_versioned_packages(
27
29
  path_to_template_package: str = typer.Argument(
28
30
  ...,
29
31
  help=(
@@ -43,6 +45,12 @@ def generate_versioned_packages(
43
45
  ),
44
46
  ) -> None:
45
47
  """For each version in the version bundle, generate a versioned package based on the template package"""
48
+ warnings.warn(
49
+ "`cadwyn generate-code-for-versioned-packages` is deprecated. Please, use `cadwyn codegen` instead",
50
+ DeprecationWarning,
51
+ stacklevel=1,
52
+ )
53
+
46
54
  from .codegen._main import generate_code_for_versioned_packages
47
55
 
48
56
  sys.path.append(str(Path.cwd()))
@@ -59,6 +67,39 @@ def generate_versioned_packages(
59
67
  )
60
68
 
61
69
 
70
+ @app.command(
71
+ name="codegen",
72
+ help=(
73
+ "For each version in the version bundle, generate a versioned package based on the "
74
+ "`latest_schema_package` package"
75
+ ),
76
+ short_help="Generate code for all versions of schemas",
77
+ )
78
+ def generate_versioned_packages(
79
+ full_path_to_version_bundle: str = typer.Argument(
80
+ ...,
81
+ help="The python path to the version bundle. Format: 'path.to.version_bundle:my_version_bundle_var'",
82
+ show_default=False,
83
+ ),
84
+ ) -> None:
85
+ from .codegen._main import generate_code_for_versioned_packages
86
+
87
+ sys.path.append(str(Path.cwd()))
88
+ path_to_version_bundle, version_bundle_variable_name = full_path_to_version_bundle.split(":")
89
+ version_bundle_module = importlib.import_module(path_to_version_bundle)
90
+ possibly_version_bundle = getattr(version_bundle_module, version_bundle_variable_name)
91
+ version_bundle = _get_version_bundle(possibly_version_bundle)
92
+
93
+ if version_bundle.latest_schemas_package is None: # pragma: no cover
94
+ raise CadwynError("VersionBundle requires a 'latest_schemas_package' argument to generate schemas.")
95
+
96
+ return generate_code_for_versioned_packages(
97
+ version_bundle.latest_schemas_package,
98
+ version_bundle,
99
+ ignore_coverage_for_latest_aliases=True,
100
+ )
101
+
102
+
62
103
  def _get_version_bundle(possibly_version_bundle: Any) -> VersionBundle:
63
104
  if not isinstance(possibly_version_bundle, VersionBundle):
64
105
  err = TypeError(
@@ -96,6 +96,7 @@ def _generate_versioned_directories(
96
96
  migration_plugins: Collection[MigrationPlugin],
97
97
  ):
98
98
  for version in versions:
99
+ print(f"Generating code for version={version.value!s}") # noqa: T201
99
100
  global_context = GlobalCodegenContext(
100
101
  current_version=version,
101
102
  versions=versions,
@@ -104,6 +105,7 @@ def _generate_versioned_directories(
104
105
  modules=modules,
105
106
  extra=extra_context,
106
107
  )
108
+
107
109
  _generate_directory_for_version(template_package, codegen_plugins, version, global_context)
108
110
  for plugin in migration_plugins:
109
111
  plugin(global_context)
@@ -117,6 +119,7 @@ def _generate_directory_for_version(
117
119
  ):
118
120
  template_dir = get_package_path_from_module(template_package)
119
121
  version_dir = get_version_dir_path(template_package, version.value)
122
+
120
123
  for (
121
124
  _relative_path_to_file,
122
125
  template_module,
@@ -24,7 +24,9 @@ from typing import (
24
24
  get_origin,
25
25
  )
26
26
 
27
+ import fastapi.params
27
28
  import fastapi.routing
29
+ import fastapi.security.base
28
30
  import fastapi.utils
29
31
  from fastapi._compat import ModelField as FastAPIModelField
30
32
  from fastapi._compat import create_body_model
@@ -472,6 +474,10 @@ class _AnnotationTransformer:
472
474
  )
473
475
  return self._change_version_of_type(annotation, version_dir)
474
476
  elif callable(annotation):
477
+ if type(annotation).__module__.startswith(
478
+ ("fastapi.", "pydantic.", "pydantic_core.", "starlette.")
479
+ ) or isinstance(annotation, fastapi.params.Security | fastapi.security.base.SecurityBase):
480
+ return annotation
475
481
 
476
482
  def modifier(annotation: Any):
477
483
  return self._change_version_of_annotations(annotation, version_dir)
@@ -545,7 +551,6 @@ def _modify_callable(
545
551
  annotation_modifying_wrapper = _copy_function(call)
546
552
  old_params = inspect.signature(call).parameters
547
553
  callable_annotations = annotation_modifying_wrapper.__annotations__
548
-
549
554
  annotation_modifying_wrapper.__annotations__ = modify_annotations(callable_annotations)
550
555
  annotation_modifying_wrapper.__defaults__ = modify_defaults(
551
556
  tuple(p.default for p in old_params.values() if p.default is not inspect.Signature.empty),
@@ -718,8 +723,7 @@ def _get_migrated_routes_by_path(version: Version) -> dict[_EndpointPath, set[_E
718
723
  def _copy_function(function: _T) -> _T:
719
724
  while hasattr(function, "__alt_wrapped__"):
720
725
  function = function.__alt_wrapped__
721
-
722
- if not isinstance(function, types.FunctionType):
726
+ if not isinstance(function, types.FunctionType | types.MethodType):
723
727
  # This means that the callable is actually an instance of a regular class
724
728
  function = function.__call__
725
729
  if inspect.iscoroutinefunction(function):
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "cadwyn"
3
- version = "3.6.5"
3
+ version = "3.7.0"
4
4
  description = "Production-ready community-driven modern Stripe-like API versioning in FastAPI"
5
5
  authors = ["Stanislav Zmiev <zmievsa@gmail.com>"]
6
6
  license = "MIT"
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes