cadwyn 3.4.1__py3-none-any.whl → 3.4.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/_utils.py CHANGED
@@ -4,7 +4,7 @@ import inspect
4
4
  from collections.abc import Callable, Collection
5
5
  from pathlib import Path
6
6
  from types import ModuleType
7
- from typing import Any, TypeVar, Union
7
+ from typing import Any, Generic, TypeVar, Union
8
8
 
9
9
  from cadwyn.exceptions import CadwynError, ModuleIsNotVersionedError
10
10
 
@@ -13,6 +13,19 @@ UnionType = type(int | str) | type(Union[int, str])
13
13
  _T = TypeVar("_T", bound=Callable)
14
14
 
15
15
 
16
+ _P_T = TypeVar("_P_T")
17
+ _P_R = TypeVar("_P_R")
18
+
19
+
20
+ class classproperty(Generic[_P_T, _P_R]): # noqa: N801
21
+ def __init__(self, func: Callable[[_P_T], _P_R]) -> None:
22
+ super().__init__()
23
+ self.func = func
24
+
25
+ def __get__(self, obj: Any, cls: _P_T) -> _P_R:
26
+ return self.func(cls)
27
+
28
+
16
29
  class PlainRepr(str):
17
30
  """String class where repr doesn't include quotes"""
18
31
 
@@ -80,7 +93,8 @@ def get_index_of_latest_schema_dir_in_module_python_path(
80
93
  # /home/myuser/package/companies/latest/__init__.py
81
94
  file = Path(file)
82
95
  _validate_that_module_is_versioned(file, version_dirs)
83
- if file.name == "__init__.py":
96
+ is_package = file.name == "__init__.py"
97
+ if is_package:
84
98
  # /home/myuser/package/companies/latest/
85
99
  file = file.parent
86
100
  # /home/myuser/package/companies
@@ -94,7 +108,12 @@ def get_index_of_latest_schema_dir_in_module_python_path(
94
108
  # ['package', 'companies', 'latest', 'schemas']
95
109
  module_split_python_path = module_python_path.split(".")
96
110
 
97
- return len(module_split_python_path) - len(relative_file_parts)
111
+ index = len(module_split_python_path) - len(relative_file_parts) - int(is_package)
112
+
113
+ # When we are in latest/__init__.py, we have this special case
114
+ if len(relative_file_parts) == 1 and is_package:
115
+ index += 1
116
+ return index
98
117
 
99
118
 
100
119
  def _validate_that_module_is_versioned(file: Path, version_dirs: Collection[Path]):
@@ -64,8 +64,9 @@ class _ImportedModule:
64
64
  module = f"{self.path}.{self.name}"
65
65
  name = ast.alias(name="*")
66
66
  level = self.how_far_up_is_base_schema_dir_from_current_module
67
- if self.is_package and level == 2:
67
+ if level == 2 and self.is_package:
68
68
  level -= 1
69
+
69
70
  return ast.ImportFrom(
70
71
  level=level,
71
72
  module=module,
@@ -93,6 +94,7 @@ def _prepare_imports_from_version_dirs(
93
94
  how_far_up_is_base_schema_dir_from_current_module = (
94
95
  len(original_module_parts) - index_of_latest_package_dir_in_pythonpath
95
96
  )
97
+
96
98
  is_package = original_module_parts[-1] == "__init__"
97
99
  if is_package:
98
100
  original_module_parts.pop(-1)
@@ -27,6 +27,7 @@ from typing_extensions import assert_never
27
27
 
28
28
  from cadwyn._compat import PYDANTIC_V2, ModelField, PydanticUndefined, model_dump
29
29
  from cadwyn._package_utils import IdentifierPythonPath, get_cls_pythonpath
30
+ from cadwyn._utils import classproperty
30
31
  from cadwyn.exceptions import CadwynError, CadwynStructureError
31
32
 
32
33
  from .._utils import Sentinel
@@ -189,9 +190,8 @@ class VersionChangeWithSideEffects(VersionChange, _abstract=True):
189
190
  f"Can't subclass {cls.__name__} as it was never meant to be subclassed.",
190
191
  )
191
192
 
192
- @classmethod
193
- @property
194
- def is_applied(cls) -> bool:
193
+ @classproperty
194
+ def is_applied(cls: type["VersionChangeWithSideEffects"]) -> bool: # pyright: ignore[reportGeneralTypeIssues]
195
195
  if (
196
196
  cls._bound_version_bundle is None
197
197
  or cls not in cls._bound_version_bundle._version_changes_to_version_mapping
@@ -294,7 +294,7 @@ class VersionBundle:
294
294
  @functools.cached_property
295
295
  def _version_changes_to_version_mapping(
296
296
  self,
297
- ) -> dict[type[VersionChange], VersionDate]:
297
+ ) -> dict[type[VersionChange] | type[VersionChangeWithSideEffects], VersionDate]:
298
298
  return {
299
299
  version_change: version.value for version in self.versions for version_change in version.version_changes
300
300
  }
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: cadwyn
3
- Version: 3.4.1
3
+ Version: 3.4.2
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
@@ -2,7 +2,7 @@ cadwyn/__init__.py,sha256=gVLVH3SSBGH0IQYGL5tbro4s0vk--9sAym0UvoG3s1w,478
2
2
  cadwyn/__main__.py,sha256=JUNmAhwn7tG1EeXI82QmFZE-fpjfAOv2kxFNDfxWbhQ,2851
3
3
  cadwyn/_compat.py,sha256=B0K-cj9bN7ytOIehOMjN9O9s0CE3lq9WAkV97pnvll8,5410
4
4
  cadwyn/_package_utils.py,sha256=trxTYLmppv-10SKhScfyDQJh21rsQGFoLaOtHycKKR0,1443
5
- cadwyn/_utils.py,sha256=gEv_1Qqp7uzvdY0u_l77d6lppAsNsOCjD8FEFBKi3Js,3758
5
+ cadwyn/_utils.py,sha256=JW3NCttM-Uj3PPW4CkYnCqROqWKOJWyHo1lcDMQillU,4274
6
6
  cadwyn/codegen/README.md,sha256=V2Kz2IOz1cTxrC-RnQ7YbWEVCIGYr3tR4IPCvepeq0M,1047
7
7
  cadwyn/codegen/__init__.py,sha256=JgddDjxMTjSfVrMXHwNu1ODgdn2QfPWpccrRKquBV6k,355
8
8
  cadwyn/codegen/_asts.py,sha256=rwg3FMC9c_20rawub98UTWzL8hhkBgJ0RdJsqnW9bVE,10161
@@ -13,7 +13,7 @@ cadwyn/codegen/_plugins/class_migrations.py,sha256=dbmXMdfUGA2X4phsNdtRQQde4SuoO
13
13
  cadwyn/codegen/_plugins/class_rebuilding.py,sha256=mJR297bqsLUfP4HW5_1GuHlpiYSQd851yHpG_ajjilg,3703
14
14
  cadwyn/codegen/_plugins/class_renaming.py,sha256=5ka2W1c18i4maNbEkEpELvGLEFbd8tthvQX3YA3Bu0A,1843
15
15
  cadwyn/codegen/_plugins/import_auto_adding.py,sha256=00zGK99cT-bq2eXKDlYBR5-Z3uHLOGU7dbhB0YFFrt0,2613
16
- cadwyn/codegen/_plugins/latest_version_aliasing.py,sha256=s8TgpBL9FofKyJaF4AB7UxJYkq-f9LiMVL33LJxFVp4,4010
16
+ cadwyn/codegen/_plugins/latest_version_aliasing.py,sha256=itVCGc1x3TRwr9O_-hcQBrVBe0P_6dNgKxuSncjX2AY,4012
17
17
  cadwyn/codegen/_plugins/module_migrations.py,sha256=TeWJk4Iu4SRQ9K2iI3v3sCs1110jrltKlPdfU9mXIsQ,722
18
18
  cadwyn/exceptions.py,sha256=XOLsT4EH1uGNirmKlkgEk03PjUMtD7tgaCDadt_eBbE,695
19
19
  cadwyn/main.py,sha256=_hC2Ke1uwtnjg2WueDXlg_QnzFgJbTcAlpHgqUBTmg4,4899
@@ -26,9 +26,9 @@ cadwyn/structure/endpoints.py,sha256=VngfAydGBwekhV2tBOtNDPVgl3X1IgYxUCw--VZ5cQY
26
26
  cadwyn/structure/enums.py,sha256=iMokxA2QYJ61SzyB-Pmuq3y7KL7-e6TsnjLVUaVZQnw,954
27
27
  cadwyn/structure/modules.py,sha256=1FK-lLm-zOTXEvn-QtyBH38aDRht5PDQiZrOPCsBlM4,1268
28
28
  cadwyn/structure/schemas.py,sha256=LIKwDuzorVC9AHg4EN-UYdI133lCk_2MkBTdiyAr-EQ,8808
29
- cadwyn/structure/versions.py,sha256=ydE16KY9oFUlsLeLh3w6-ZDulwtya9-U0rTxtA3EaKE,28245
30
- cadwyn-3.4.1.dist-info/entry_points.txt,sha256=eO05hLn9GoRzzpwT9GONPmXKsonjuMNssM2D2WHWKGk,46
31
- cadwyn-3.4.1.dist-info/LICENSE,sha256=KeCWewiDQYpmSnzF-p_0YpoWiyDcUPaCuG8OWQs4ig4,1072
32
- cadwyn-3.4.1.dist-info/WHEEL,sha256=vxFmldFsRN_Hx10GDvsdv1wroKq8r5Lzvjp6GZ4OO8c,88
33
- cadwyn-3.4.1.dist-info/METADATA,sha256=bJR5wfSCg_UftVxkz2ZeahBW_7oCuik6bRsABe62EfE,4264
34
- cadwyn-3.4.1.dist-info/RECORD,,
29
+ cadwyn/structure/versions.py,sha256=kmIJTJpihXsCnE7-7PT82nIcW3qkOtN5ewuF3bxnamc,28392
30
+ cadwyn-3.4.2.dist-info/entry_points.txt,sha256=eO05hLn9GoRzzpwT9GONPmXKsonjuMNssM2D2WHWKGk,46
31
+ cadwyn-3.4.2.dist-info/LICENSE,sha256=KeCWewiDQYpmSnzF-p_0YpoWiyDcUPaCuG8OWQs4ig4,1072
32
+ cadwyn-3.4.2.dist-info/WHEEL,sha256=vxFmldFsRN_Hx10GDvsdv1wroKq8r5Lzvjp6GZ4OO8c,88
33
+ cadwyn-3.4.2.dist-info/METADATA,sha256=s4cO22vjgaJU5gokr8L2_-osjw4ufSZhE6CYY7Vi6O8,4264
34
+ cadwyn-3.4.2.dist-info/RECORD,,
File without changes