django-compose 0.1.0.dev10__tar.gz → 0.1.0.dev12__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.
Files changed (104) hide show
  1. {django_compose-0.1.0.dev10 → django_compose-0.1.0.dev12}/CHANGELOG.md +22 -0
  2. {django_compose-0.1.0.dev10 → django_compose-0.1.0.dev12}/PKG-INFO +1 -1
  3. {django_compose-0.1.0.dev10 → django_compose-0.1.0.dev12}/docs/SPEC.md +7 -0
  4. {django_compose-0.1.0.dev10 → django_compose-0.1.0.dev12}/docs/components.md +7 -2
  5. {django_compose-0.1.0.dev10 → django_compose-0.1.0.dev12}/pyproject.toml +1 -1
  6. {django_compose-0.1.0.dev10 → django_compose-0.1.0.dev12}/src/django_compose/components.py +34 -1
  7. {django_compose-0.1.0.dev10 → django_compose-0.1.0.dev12}/src/django_compose/typing.py +31 -13
  8. {django_compose-0.1.0.dev10 → django_compose-0.1.0.dev12}/tests/test_components.py +26 -0
  9. {django_compose-0.1.0.dev10 → django_compose-0.1.0.dev12}/tests/test_typing.py +15 -0
  10. {django_compose-0.1.0.dev10 → django_compose-0.1.0.dev12}/tests/typing_fixtures/__init__.py +65 -0
  11. {django_compose-0.1.0.dev10 → django_compose-0.1.0.dev12}/uv.lock +1 -1
  12. {django_compose-0.1.0.dev10 → django_compose-0.1.0.dev12}/.gitignore +0 -0
  13. {django_compose-0.1.0.dev10 → django_compose-0.1.0.dev12}/AGENTS.md +0 -0
  14. {django_compose-0.1.0.dev10 → django_compose-0.1.0.dev12}/CONTRIBUTING.md +0 -0
  15. {django_compose-0.1.0.dev10 → django_compose-0.1.0.dev12}/COPYING +0 -0
  16. {django_compose-0.1.0.dev10 → django_compose-0.1.0.dev12}/LICENSE +0 -0
  17. {django_compose-0.1.0.dev10 → django_compose-0.1.0.dev12}/Makefile +0 -0
  18. {django_compose-0.1.0.dev10 → django_compose-0.1.0.dev12}/NOTICE +0 -0
  19. {django_compose-0.1.0.dev10 → django_compose-0.1.0.dev12}/README.md +0 -0
  20. {django_compose-0.1.0.dev10 → django_compose-0.1.0.dev12}/docs/README.md +0 -0
  21. {django_compose-0.1.0.dev10 → django_compose-0.1.0.dev12}/docs/ROADMAP.md +0 -0
  22. {django_compose-0.1.0.dev10 → django_compose-0.1.0.dev12}/docs/api.md +0 -0
  23. {django_compose-0.1.0.dev10 → django_compose-0.1.0.dev12}/docs/configuration.md +0 -0
  24. {django_compose-0.1.0.dev10 → django_compose-0.1.0.dev12}/docs/dependencies.md +0 -0
  25. {django_compose-0.1.0.dev10 → django_compose-0.1.0.dev12}/docs/extensions.md +0 -0
  26. {django_compose-0.1.0.dev10 → django_compose-0.1.0.dev12}/docs/migrations.md +0 -0
  27. {django_compose-0.1.0.dev10 → django_compose-0.1.0.dev12}/docs/models.md +0 -0
  28. {django_compose-0.1.0.dev10 → django_compose-0.1.0.dev12}/docs/packaging.md +0 -0
  29. {django_compose-0.1.0.dev10 → django_compose-0.1.0.dev12}/docs/proposals/0001-native-url-collisions.md +0 -0
  30. {django_compose-0.1.0.dev10 → django_compose-0.1.0.dev12}/docs/proposals/0002-supplied-distribution-metadata.md +0 -0
  31. {django_compose-0.1.0.dev10 → django_compose-0.1.0.dev12}/docs/proposals/0004-serving-boundary.md +0 -0
  32. {django_compose-0.1.0.dev10 → django_compose-0.1.0.dev12}/docs/proposals/README.md +0 -0
  33. {django_compose-0.1.0.dev10 → django_compose-0.1.0.dev12}/docs/provisioning.md +0 -0
  34. {django_compose-0.1.0.dev10 → django_compose-0.1.0.dev12}/docs/quickstart.md +0 -0
  35. {django_compose-0.1.0.dev10 → django_compose-0.1.0.dev12}/examples/shop/.gitignore +0 -0
  36. {django_compose-0.1.0.dev10 → django_compose-0.1.0.dev12}/examples/shop/README.md +0 -0
  37. {django_compose-0.1.0.dev10 → django_compose-0.1.0.dev12}/examples/shop/catalog/__init__.py +0 -0
  38. {django_compose-0.1.0.dev10 → django_compose-0.1.0.dev12}/examples/shop/catalog/apps.py +0 -0
  39. {django_compose-0.1.0.dev10 → django_compose-0.1.0.dev12}/examples/shop/catalog/autoconfig.py +0 -0
  40. {django_compose-0.1.0.dev10 → django_compose-0.1.0.dev12}/examples/shop/catalog/integrations.py +0 -0
  41. {django_compose-0.1.0.dev10 → django_compose-0.1.0.dev12}/examples/shop/catalog/models.py +0 -0
  42. {django_compose-0.1.0.dev10 → django_compose-0.1.0.dev12}/examples/shop/catalog/pyproject.toml +0 -0
  43. {django_compose-0.1.0.dev10 → django_compose-0.1.0.dev12}/examples/shop/catalog/schema.py +0 -0
  44. {django_compose-0.1.0.dev10 → django_compose-0.1.0.dev12}/examples/shop/catalog/urls.py +0 -0
  45. {django_compose-0.1.0.dev10 → django_compose-0.1.0.dev12}/examples/shop/manage.py +0 -0
  46. {django_compose-0.1.0.dev10 → django_compose-0.1.0.dev12}/examples/shop/reviews/__init__.py +0 -0
  47. {django_compose-0.1.0.dev10 → django_compose-0.1.0.dev12}/examples/shop/reviews/apps.py +0 -0
  48. {django_compose-0.1.0.dev10 → django_compose-0.1.0.dev12}/examples/shop/reviews/autoconfig.py +0 -0
  49. {django_compose-0.1.0.dev10 → django_compose-0.1.0.dev12}/examples/shop/reviews/models.py +0 -0
  50. {django_compose-0.1.0.dev10 → django_compose-0.1.0.dev12}/examples/shop/reviews/pyproject.toml +0 -0
  51. {django_compose-0.1.0.dev10 → django_compose-0.1.0.dev12}/examples/shop/settings.py +0 -0
  52. {django_compose-0.1.0.dev10 → django_compose-0.1.0.dev12}/examples/shop/urls.py +0 -0
  53. {django_compose-0.1.0.dev10 → django_compose-0.1.0.dev12}/examples/shop/verify.py +0 -0
  54. {django_compose-0.1.0.dev10 → django_compose-0.1.0.dev12}/scripts/check_distribution.py +0 -0
  55. {django_compose-0.1.0.dev10 → django_compose-0.1.0.dev12}/src/django_compose/__init__.py +0 -0
  56. {django_compose-0.1.0.dev10 → django_compose-0.1.0.dev12}/src/django_compose/__main__.py +0 -0
  57. {django_compose-0.1.0.dev10 → django_compose-0.1.0.dev12}/src/django_compose/apps.py +0 -0
  58. {django_compose-0.1.0.dev10 → django_compose-0.1.0.dev12}/src/django_compose/artifacts.py +0 -0
  59. {django_compose-0.1.0.dev10 → django_compose-0.1.0.dev12}/src/django_compose/autoreload.py +0 -0
  60. {django_compose-0.1.0.dev10 → django_compose-0.1.0.dev12}/src/django_compose/build.py +0 -0
  61. {django_compose-0.1.0.dev10 → django_compose-0.1.0.dev12}/src/django_compose/cli.py +0 -0
  62. {django_compose-0.1.0.dev10 → django_compose-0.1.0.dev12}/src/django_compose/conf.py +0 -0
  63. {django_compose-0.1.0.dev10 → django_compose-0.1.0.dev12}/src/django_compose/declarations.py +0 -0
  64. {django_compose-0.1.0.dev10 → django_compose-0.1.0.dev12}/src/django_compose/history.py +0 -0
  65. {django_compose-0.1.0.dev10 → django_compose-0.1.0.dev12}/src/django_compose/management/__init__.py +0 -0
  66. {django_compose-0.1.0.dev10 → django_compose-0.1.0.dev12}/src/django_compose/management/commands/__init__.py +0 -0
  67. {django_compose-0.1.0.dev10 → django_compose-0.1.0.dev12}/src/django_compose/management/commands/check_migrations.py +0 -0
  68. {django_compose-0.1.0.dev10 → django_compose-0.1.0.dev12}/src/django_compose/management/commands/compose.py +0 -0
  69. {django_compose-0.1.0.dev10 → django_compose-0.1.0.dev12}/src/django_compose/management/commands/makemigrations.py +0 -0
  70. {django_compose-0.1.0.dev10 → django_compose-0.1.0.dev12}/src/django_compose/management/commands/migrate.py +0 -0
  71. {django_compose-0.1.0.dev10 → django_compose-0.1.0.dev12}/src/django_compose/management/commands/provision.py +0 -0
  72. {django_compose-0.1.0.dev10 → django_compose-0.1.0.dev12}/src/django_compose/management/commands/reset_migration_history.py +0 -0
  73. {django_compose-0.1.0.dev10 → django_compose-0.1.0.dev12}/src/django_compose/management/commands/retire_history.py +0 -0
  74. {django_compose-0.1.0.dev10 → django_compose-0.1.0.dev12}/src/django_compose/migration_imports.py +0 -0
  75. {django_compose-0.1.0.dev10 → django_compose-0.1.0.dev12}/src/django_compose/migrations.py +0 -0
  76. {django_compose-0.1.0.dev10 → django_compose-0.1.0.dev12}/src/django_compose/model_composition.py +0 -0
  77. {django_compose-0.1.0.dev10 → django_compose-0.1.0.dev12}/src/django_compose/models.py +0 -0
  78. {django_compose-0.1.0.dev10 → django_compose-0.1.0.dev12}/src/django_compose/provision.py +0 -0
  79. {django_compose-0.1.0.dev10 → django_compose-0.1.0.dev12}/src/django_compose/py.typed +0 -0
  80. {django_compose-0.1.0.dev10 → django_compose-0.1.0.dev12}/src/django_compose/rendering.py +0 -0
  81. {django_compose-0.1.0.dev10 → django_compose-0.1.0.dev12}/src/django_compose/serving.py +0 -0
  82. {django_compose-0.1.0.dev10 → django_compose-0.1.0.dev12}/src/django_compose/snapshot.py +0 -0
  83. {django_compose-0.1.0.dev10 → django_compose-0.1.0.dev12}/src/django_compose/sources.py +0 -0
  84. {django_compose-0.1.0.dev10 → django_compose-0.1.0.dev12}/tests/core_fixtures/__init__.py +0 -0
  85. {django_compose-0.1.0.dev10 → django_compose-0.1.0.dev12}/tests/test_artifacts.py +0 -0
  86. {django_compose-0.1.0.dev10 → django_compose-0.1.0.dev12}/tests/test_autoreload.py +0 -0
  87. {django_compose-0.1.0.dev10 → django_compose-0.1.0.dev12}/tests/test_bootstrap.py +0 -0
  88. {django_compose-0.1.0.dev10 → django_compose-0.1.0.dev12}/tests/test_boundaries.py +0 -0
  89. {django_compose-0.1.0.dev10 → django_compose-0.1.0.dev12}/tests/test_conf.py +0 -0
  90. {django_compose-0.1.0.dev10 → django_compose-0.1.0.dev12}/tests/test_history.py +0 -0
  91. {django_compose-0.1.0.dev10 → django_compose-0.1.0.dev12}/tests/test_initial_history.py +0 -0
  92. {django_compose-0.1.0.dev10 → django_compose-0.1.0.dev12}/tests/test_integrations.py +0 -0
  93. {django_compose-0.1.0.dev10 → django_compose-0.1.0.dev12}/tests/test_launcher.py +0 -0
  94. {django_compose-0.1.0.dev10 → django_compose-0.1.0.dev12}/tests/test_migration_imports.py +0 -0
  95. {django_compose-0.1.0.dev10 → django_compose-0.1.0.dev12}/tests/test_migration_scaffold.py +0 -0
  96. {django_compose-0.1.0.dev10 → django_compose-0.1.0.dev12}/tests/test_migrations.py +0 -0
  97. {django_compose-0.1.0.dev10 → django_compose-0.1.0.dev12}/tests/test_migrations_guards.py +0 -0
  98. {django_compose-0.1.0.dev10 → django_compose-0.1.0.dev12}/tests/test_migrations_postgres.py +0 -0
  99. {django_compose-0.1.0.dev10 → django_compose-0.1.0.dev12}/tests/test_models.py +0 -0
  100. {django_compose-0.1.0.dev10 → django_compose-0.1.0.dev12}/tests/test_provision.py +0 -0
  101. {django_compose-0.1.0.dev10 → django_compose-0.1.0.dev12}/tests/test_provision_postgres.py +0 -0
  102. {django_compose-0.1.0.dev10 → django_compose-0.1.0.dev12}/tests/test_snapshot.py +0 -0
  103. {django_compose-0.1.0.dev10 → django_compose-0.1.0.dev12}/tests/test_sources.py +0 -0
  104. {django_compose-0.1.0.dev10 → django_compose-0.1.0.dev12}/tests/test_startup.py +0 -0
@@ -1,5 +1,27 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.1.0.dev12
4
+
5
+ - Rebase each composition target on its own target first in `django_compose.typing`,
6
+ so no source, donor or `demands` mixin is linearized over a partial ancestry.
7
+ Depending on declaration and import order, a source or donor analyzed before its
8
+ parent was rebased was not a subtype of that parent's ancestors, and the generated
9
+ concrete model kept mypy's placeholder MRO: it was neither a `Model` nor a subtype
10
+ of its source, and consumers saw only the resulting assignment and attribute errors.
11
+
12
+ ## 0.1.0.dev11
13
+
14
+ - Reuse the `installed_components(group)` index for the same group and `sys.path`
15
+ until `importlib.invalidate_caches()` runs, instead of re-reading every installed
16
+ distribution's metadata on each call: with 280 distributions a call fell from
17
+ about 40 ms to a lookup. A process that installs or writes distribution metadata
18
+ at runtime invalidates the import caches before indexing again, as before
19
+ importing new modules. Code that replaces `importlib.metadata` functions, such
20
+ as a test that monkeypatches `metadata.distributions`, must call
21
+ `importlib.invalidate_caches()` too; `monkeypatch.syspath_prepend` already does.
22
+ - Register the cache's invalidation hook on `sys.meta_path` once per process,
23
+ including across `importlib.reload` of `django_compose.components`.
24
+
3
25
  ## 0.1.0.dev10
4
26
 
5
27
  - Answer directory and editable-project distribution ownership by key from the one
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: django-compose
3
- Version: 0.1.0.dev10
3
+ Version: 0.1.0.dev12
4
4
  Summary: Compose reusable Django apps into a runnable project.
5
5
  Project-URL: Source, https://github.com/ang-ee/django-compose
6
6
  Project-URL: Documentation, https://github.com/ang-ee/django-compose/tree/main/docs
@@ -166,6 +166,13 @@ nor checks importability, actual AppConfig identity or installed dependencies.
166
166
 
167
167
  `components.installed_components(group)` selects each canonical installed name's
168
168
  native `metadata.distribution()` winner, then delegates to that same index owner.
169
+ The index is reused for the same group and `sys.path` until
170
+ `importlib.invalidate_caches()` runs. A process that installs or writes
171
+ distribution metadata at runtime invalidates the import caches before indexing
172
+ again, as it must before importing modules written at runtime. Code that
173
+ replaces `importlib.metadata` functions, such as a test that monkeypatches
174
+ `metadata.distributions`, must call `importlib.invalidate_caches()` too;
175
+ pytest's `monkeypatch.syspath_prepend` already calls it.
169
176
  `active_requirements(iterable_of_strings)` and the index method
170
177
  `active_requirements(provider)` return native Requirement values active with
171
178
  `extra=""`. Metadata inspection does not activate apps.
@@ -145,8 +145,13 @@ an explicitly empty or invalid group fails. `configure` uses this same helper.
145
145
 
146
146
  `installed_components(group)` returns an `InstalledComponents` index of native
147
147
  distribution and entry-point objects without importing apps or loading entry
148
- points. To inspect metadata prepared separately by a package build backend, pass
149
- native `Distribution` objects to the same indexing owner:
148
+ points. The index is reused for the same group and `sys.path`; after installing
149
+ or writing distribution metadata at runtime, call `importlib.invalidate_caches()`
150
+ before indexing again, as before importing new modules. Code that replaces
151
+ `importlib.metadata` functions, such as a test that monkeypatches
152
+ `metadata.distributions`, must call it too; pytest's `monkeypatch.syspath_prepend`
153
+ already does. To inspect metadata prepared separately by a package build
154
+ backend, pass native `Distribution` objects to the same indexing owner:
150
155
 
151
156
  ```python
152
157
  from importlib.metadata import Distribution
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "django-compose"
7
- version = "0.1.0.dev10"
7
+ version = "0.1.0.dev12"
8
8
  description = "Compose reusable Django apps into a runnable project."
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.14"
@@ -2,6 +2,7 @@
2
2
 
3
3
  from __future__ import annotations
4
4
 
5
+ import functools
5
6
  import json
6
7
  import math
7
8
  import os
@@ -218,8 +219,18 @@ def index_components(distributions: Iterable[metadata.Distribution], *, group: s
218
219
 
219
220
 
220
221
  def installed_components(group: str) -> InstalledComponents:
221
- """Index installed metadata using native same-name installation precedence."""
222
+ """Index installed metadata using native same-name installation precedence.
222
223
 
224
+ The index is reused for the same group and import path until
225
+ importlib.invalidate_caches() runs, which a process that installs or writes
226
+ distribution metadata at runtime calls before discovering it, as for imports.
227
+ Code that replaces importlib.metadata functions must call it too.
228
+ """
229
+ return _installed_components(group, tuple(sys.path))
230
+
231
+
232
+ @functools.lru_cache(maxsize=8)
233
+ def _installed_components(group: str, path: tuple[str, ...]) -> InstalledComponents:
223
234
  def distributions() -> Iterator[metadata.Distribution]:
224
235
  names = {canonicalize_name(dist.metadata["Name"]) for dist in metadata.distributions()}
225
236
  for name in sorted(names):
@@ -228,6 +239,28 @@ def installed_components(group: str) -> InstalledComponents:
228
239
  return index_components(distributions(), group=group)
229
240
 
230
241
 
242
+ class _InstalledComponentsFinder:
243
+ """Find nothing; let importlib.invalidate_caches() clear the installed index."""
244
+
245
+ @staticmethod
246
+ def find_spec(*args: object) -> None:
247
+ return None
248
+
249
+ @staticmethod
250
+ def invalidate_caches() -> None:
251
+ _installed_components.cache_clear()
252
+
253
+
254
+ # A reload re-runs this module in the same namespace, where a registered finder
255
+ # already clears the new cache; register once per process.
256
+ if not any(
257
+ getattr(finder, "__module__", None) == __name__
258
+ and getattr(finder, "__qualname__", None) == _InstalledComponentsFinder.__qualname__
259
+ for finder in sys.meta_path
260
+ ):
261
+ sys.meta_path.append(_InstalledComponentsFinder)
262
+
263
+
231
264
  def enabled_apps(roots: Iterable[str], *, group: str | None = None) -> Closure:
232
265
  """Expand explicit roots using installed providers and selected requires_apps.
233
266
 
@@ -356,23 +356,13 @@ class CompositionPlugin(NewSemanalDjangoPlugin):
356
356
  def _model_contract(self, ctx: ClassDefContext, *, native: Callable[[ClassDefContext], None]) -> None:
357
357
  parent_name = self.django_context.parents.get(ctx.cls.fullname)
358
358
  if parent_name:
359
- parent = self.lookup_fully_qualified(parent_name)
360
- if parent is None or not isinstance(parent.node, TypeInfo) or not parent.node.mro:
359
+ unresolved = self._rebase(ctx.cls.info, complete=not ctx.api.final_iteration)
360
+ if unresolved:
361
361
  if ctx.api.final_iteration:
362
- ctx.api.fail(f"Unresolved composition target {parent_name}", ctx.cls)
362
+ ctx.api.fail(f"Unresolved composition target {unresolved}", ctx.cls)
363
363
  else:
364
364
  ctx.api.defer()
365
365
  return
366
- if not any(base.type.has_base(parent_name) for base in ctx.cls.info.bases):
367
- ancestors = {base.fullname for base in parent.node.mro}
368
- instance = fill_typevars(parent.node)
369
- assert isinstance(instance, Instance)
370
- ctx.cls.info.bases = [
371
- *[base for base in ctx.cls.info.bases if base.type.fullname not in ancestors],
372
- instance,
373
- ]
374
- ctx.cls.info.mro = []
375
- calculate_mro(ctx.cls.info)
376
366
  ctx.api.add_plugin_dependency(make_trigger(parent_name))
377
367
  native(ctx)
378
368
  runtime = self.django_context.get_model_class_by_fullname(ctx.cls.fullname)
@@ -402,6 +392,34 @@ class CompositionPlugin(NewSemanalDjangoPlugin):
402
392
  if ctx.cls.fullname in self.django_context.members:
403
393
  self._schedule_projection(ctx, ctx.cls.info)
404
394
 
395
+ def _rebase(self, info: TypeInfo, *, complete: bool) -> str | None:
396
+ """Rebase a source, donor or demanding class on its composition target.
397
+
398
+ The target is rebased on its own target first. Mypy linearizes each class
399
+ once and reuses that MRO for every subclass, including the generated
400
+ concrete class, so no class may be rebased on an ancestry that a later
401
+ rebase would still change. Return the unresolved target name instead:
402
+ any in the chain when ``complete``, otherwise only the direct target.
403
+ """
404
+
405
+ parent_name = self.django_context.parents.get(info.fullname)
406
+ if parent_name is None:
407
+ return None
408
+ parent = self.lookup_fully_qualified(parent_name)
409
+ if parent is None or not isinstance(parent.node, TypeInfo) or not parent.node.mro:
410
+ return parent_name
411
+ unresolved = self._rebase(parent.node, complete=complete)
412
+ if unresolved and complete:
413
+ return unresolved
414
+ if not any(base.type.has_base(parent_name) for base in info.bases):
415
+ ancestors = {base.fullname for base in parent.node.mro}
416
+ instance = fill_typevars(parent.node)
417
+ assert isinstance(instance, Instance)
418
+ info.bases = [*[base for base in info.bases if base.type.fullname not in ancestors], instance]
419
+ info.mro = []
420
+ calculate_mro(info)
421
+ return None
422
+
405
423
  def project_model(self, ctx: ClassDefContext, model: type[models.Model]) -> TypeInfo | None:
406
424
  """Project a supplied native model lacking a source declaration in memory.
407
425
 
@@ -509,6 +509,32 @@ def test_active_requirements_are_native_platform_filtered_and_extra_empty(instal
509
509
  assert str(requirements[1].specifier) == ">=1"
510
510
 
511
511
 
512
+ def test_installed_index_is_reused_until_import_caches_or_the_path_change(installed, monkeypatch, tmp_path):
513
+ installed.distribution("first-provider", app="first_app")
514
+ index = installed_components(GROUP)
515
+ installed.distribution("second-provider", app="second_app")
516
+ assert installed_components(GROUP) is index
517
+ importlib.invalidate_caches()
518
+ assert set(installed_components(GROUP).providers) == {"first_app", "second_app"}
519
+ installed.distribution("third-provider", app="third_app")
520
+ monkeypatch.setattr(sys, "path", [*sys.path, str(tmp_path / "elsewhere")])
521
+ assert set(installed_components(GROUP).providers) == {"first_app", "second_app", "third_app"}
522
+
523
+
524
+ def test_reloaded_components_keep_one_hook_that_clears_the_new_index():
525
+ script = (
526
+ "import importlib, sys\n"
527
+ "from django_compose import components\n"
528
+ "importlib.reload(components)\n"
529
+ "hooks = [f for f in sys.meta_path if getattr(f, '__module__', None) == components.__name__]\n"
530
+ "components.installed_components('testsite.none')\n"
531
+ "importlib.invalidate_caches()\n"
532
+ "print(len(hooks), components._installed_components.cache_info().currsize)\n"
533
+ )
534
+ result = subprocess.run([sys.executable, "-c", script], capture_output=True, text=True, check=True)
535
+ assert result.stdout.split() == ["1", "0"]
536
+
537
+
512
538
  @pytest.mark.parametrize("kind", ("provider", "entries"))
513
539
  def test_installed_index_rejects_metadata_collisions_without_activation(installed, kind):
514
540
  installed.distribution(
@@ -371,6 +371,21 @@ def test_native_c3_source_precedes_later_donor_ancestor(tmp_path):
371
371
  assert result.returncode == 0, result.stdout + result.stderr
372
372
 
373
373
 
374
+ @pytest.mark.parametrize("source_first", [False, True])
375
+ def test_generated_model_linearizes_completely_rebased_ancestry(tmp_path, source_first):
376
+ from typing_fixtures import CHAIN_CONSUMER, CHAIN_DONOR, CHAIN_MODELS, CHAIN_SOURCE, CHAIN_TARGET
377
+
378
+ config, env = host(tmp_path)
379
+ middle = (CHAIN_SOURCE, CHAIN_TARGET) if source_first else (CHAIN_TARGET, CHAIN_SOURCE)
380
+ (tmp_path / "modelapp/models.py").write_text(CHAIN_MODELS.format(middle="".join(middle)))
381
+ (tmp_path / "modelapp/donors.py").write_text(CHAIN_DONOR)
382
+ source = tmp_path / "consumer.py"
383
+ source.write_text(CHAIN_CONSUMER)
384
+ for _ in range(2):
385
+ result = check(config, env, source)
386
+ assert result.returncode == 0, result.stdout + result.stderr
387
+
388
+
374
389
  def test_union_receivers_keep_each_native_member_owner_and_binding(tmp_path):
375
390
  config, env = host(tmp_path)
376
391
  model = tmp_path / "modelapp/models.py"
@@ -349,3 +349,68 @@ def invalid_relations(row: RuntimeRow, anchor: Anchor) -> None:
349
349
  anchor.m2m_rows.add(anchor)
350
350
  anchor.member_rows.add(anchor)
351
351
  """
352
+
353
+ # A parent chain whose root is declared last: the middle target becomes
354
+ # resolvable, and is rebased on the root, one semantic-analysis iteration late.
355
+ CHAIN_MODELS = """
356
+ from django.db import models
357
+ from django_compose.models import Composable
358
+ class Archive(Composable):
359
+ def archive(self) -> bool:
360
+ return True
361
+ class Meta:
362
+ abstract = True
363
+ {middle}
364
+ class Party(Archive, Composable, concrete=True):
365
+ name = models.CharField(max_length=30)
366
+ class Meta:
367
+ abstract = True
368
+ from .donors import CompanyBilling as CompanyBilling
369
+ """
370
+
371
+ CHAIN_TARGET = """
372
+ class Organization(Composable, inherits="modelapp.Party"):
373
+ legal_name = models.CharField(max_length=30)
374
+ class Meta:
375
+ abstract = True
376
+ """
377
+
378
+ CHAIN_SOURCE = """
379
+ class Company(Archive, Composable, inherits="modelapp.Organization"):
380
+ code = models.CharField(max_length=30)
381
+ class Meta:
382
+ abstract = True
383
+ """
384
+
385
+ CHAIN_DONOR = """
386
+ from django.db import models
387
+ from django_compose.models import Composable
388
+ class CompanyBilling(Composable, extends="modelapp.Company"):
389
+ vat = models.CharField(max_length=30)
390
+ def billed(self) -> int:
391
+ return 1
392
+ class Meta:
393
+ abstract = True
394
+ """
395
+
396
+ CHAIN_CONSUMER = """
397
+ from typing import assert_type
398
+ from django.db import models
399
+ from modelapp.models import Company, CompanyBilling, Organization, Party
400
+ from typed_runtime.modelapp.models import Company as ConcreteCompany
401
+
402
+ def check(concrete: ConcreteCompany, company: Company, billing: CompanyBilling) -> None:
403
+ model: models.Model = concrete
404
+ source: Company = concrete
405
+ donor: CompanyBilling = concrete
406
+ parent: Organization = concrete
407
+ root: Party = company
408
+ donor_root: Party = billing
409
+ assert_type(concrete.code, str)
410
+ assert_type(concrete.vat, str)
411
+ assert_type(concrete.billed(), int)
412
+ assert_type(concrete.legal_name, str)
413
+ assert_type(concrete.name, str)
414
+ assert_type(concrete.archive(), bool)
415
+ assert_type(ConcreteCompany.objects.get(), ConcreteCompany)
416
+ """
@@ -348,7 +348,7 @@ wheels = [
348
348
 
349
349
  [[package]]
350
350
  name = "django-compose"
351
- version = "0.1.0.dev10"
351
+ version = "0.1.0.dev12"
352
352
  source = { editable = "." }
353
353
  dependencies = [
354
354
  { name = "django" },