xtr-maker 7.0.0__tar.gz → 7.2.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.
Files changed (71) hide show
  1. {xtr_maker-7.0.0 → xtr_maker-7.2.0}/PKG-INFO +31 -1
  2. {xtr_maker-7.0.0 → xtr_maker-7.2.0}/README.md +30 -0
  3. {xtr_maker-7.0.0 → xtr_maker-7.2.0}/pyproject.toml +2 -1
  4. {xtr_maker-7.0.0 → xtr_maker-7.2.0}/pyproject.toml.orig +3 -1
  5. {xtr_maker-7.0.0 → xtr_maker-7.2.0}/src/xtr_maker/.agents/skills/xtr-maker/SKILL.md +11 -0
  6. {xtr_maker-7.0.0 → xtr_maker-7.2.0}/src/xtr_maker/bundle/maker_bundle.py +1 -0
  7. xtr_maker-7.2.0/src/xtr_maker/command/make_fixtures_command.py +122 -0
  8. {xtr_maker-7.0.0 → xtr_maker-7.2.0}/src/xtr_maker/event/event_registry.py +2 -1
  9. xtr_maker-7.2.0/src/xtr_maker/templates/fixtures/fixtures.py.jinja +23 -0
  10. {xtr_maker-7.0.0 → xtr_maker-7.2.0}/LICENSE +0 -0
  11. {xtr_maker-7.0.0 → xtr_maker-7.2.0}/src/xtr_maker/__init__.py +0 -0
  12. {xtr_maker-7.0.0 → xtr_maker-7.2.0}/src/xtr_maker/bundle/__init__.py +0 -0
  13. {xtr_maker-7.0.0 → xtr_maker-7.2.0}/src/xtr_maker/bundle/maker_config.py +0 -0
  14. {xtr_maker-7.0.0 → xtr_maker-7.2.0}/src/xtr_maker/class_name.py +0 -0
  15. {xtr_maker-7.0.0 → xtr_maker-7.2.0}/src/xtr_maker/command/__init__.py +0 -0
  16. {xtr_maker-7.0.0 → xtr_maker-7.2.0}/src/xtr_maker/command/_request_matchers.py +0 -0
  17. {xtr_maker-7.0.0 → xtr_maker-7.2.0}/src/xtr_maker/command/_schedule_source.py +0 -0
  18. {xtr_maker-7.0.0 → xtr_maker-7.2.0}/src/xtr_maker/command/_webhook_names.py +0 -0
  19. {xtr_maker-7.0.0 → xtr_maker-7.2.0}/src/xtr_maker/command/make_command_command.py +0 -0
  20. {xtr_maker-7.0.0 → xtr_maker-7.2.0}/src/xtr_maker/command/make_entity_command.py +0 -0
  21. {xtr_maker-7.0.0 → xtr_maker-7.2.0}/src/xtr_maker/command/make_listener_command.py +0 -0
  22. {xtr_maker-7.0.0 → xtr_maker-7.2.0}/src/xtr_maker/command/make_message_command.py +0 -0
  23. {xtr_maker-7.0.0 → xtr_maker-7.2.0}/src/xtr_maker/command/make_migration_command.py +0 -0
  24. {xtr_maker-7.0.0 → xtr_maker-7.2.0}/src/xtr_maker/command/make_schedule_command.py +0 -0
  25. {xtr_maker-7.0.0 → xtr_maker-7.2.0}/src/xtr_maker/command/make_webhook_command.py +0 -0
  26. {xtr_maker-7.0.0 → xtr_maker-7.2.0}/src/xtr_maker/command_parameter.py +0 -0
  27. {xtr_maker-7.0.0 → xtr_maker-7.2.0}/src/xtr_maker/command_source.py +0 -0
  28. {xtr_maker-7.0.0 → xtr_maker-7.2.0}/src/xtr_maker/entity/__init__.py +0 -0
  29. {xtr_maker-7.0.0 → xtr_maker-7.2.0}/src/xtr_maker/entity/entity_field.py +0 -0
  30. {xtr_maker-7.0.0 → xtr_maker-7.2.0}/src/xtr_maker/entity/entity_interviewer.py +0 -0
  31. {xtr_maker-7.0.0 → xtr_maker-7.2.0}/src/xtr_maker/entity/entity_relation.py +0 -0
  32. {xtr_maker-7.0.0 → xtr_maker-7.2.0}/src/xtr_maker/entity/entity_source_editor.py +0 -0
  33. {xtr_maker-7.0.0 → xtr_maker-7.2.0}/src/xtr_maker/entity/entity_workspace.py +0 -0
  34. {xtr_maker-7.0.0 → xtr_maker-7.2.0}/src/xtr_maker/entity/field_type.py +0 -0
  35. {xtr_maker-7.0.0 → xtr_maker-7.2.0}/src/xtr_maker/entity/id_type.py +0 -0
  36. {xtr_maker-7.0.0 → xtr_maker-7.2.0}/src/xtr_maker/entity/import_merger.py +0 -0
  37. {xtr_maker-7.0.0 → xtr_maker-7.2.0}/src/xtr_maker/entity/mapped_attribute.py +0 -0
  38. {xtr_maker-7.0.0 → xtr_maker-7.2.0}/src/xtr_maker/entity/needed_import.py +0 -0
  39. {xtr_maker-7.0.0 → xtr_maker-7.2.0}/src/xtr_maker/entity/property_name.py +0 -0
  40. {xtr_maker-7.0.0 → xtr_maker-7.2.0}/src/xtr_maker/entity/relation_kind.py +0 -0
  41. {xtr_maker-7.0.0 → xtr_maker-7.2.0}/src/xtr_maker/entity/relation_writer.py +0 -0
  42. {xtr_maker-7.0.0 → xtr_maker-7.2.0}/src/xtr_maker/event/__init__.py +0 -0
  43. {xtr_maker-7.0.0 → xtr_maker-7.2.0}/src/xtr_maker/event/known_event.py +0 -0
  44. {xtr_maker-7.0.0 → xtr_maker-7.2.0}/src/xtr_maker/exception/__init__.py +0 -0
  45. {xtr_maker-7.0.0 → xtr_maker-7.2.0}/src/xtr_maker/exception/app_package_not_found_error.py +0 -0
  46. {xtr_maker-7.0.0 → xtr_maker-7.2.0}/src/xtr_maker/exception/generated_source_error.py +0 -0
  47. {xtr_maker-7.0.0 → xtr_maker-7.2.0}/src/xtr_maker/exception/invalid_argument_error.py +0 -0
  48. {xtr_maker-7.0.0 → xtr_maker-7.2.0}/src/xtr_maker/exception/invalid_class_name_error.py +0 -0
  49. {xtr_maker-7.0.0 → xtr_maker-7.2.0}/src/xtr_maker/exception/maker_error.py +0 -0
  50. {xtr_maker-7.0.0 → xtr_maker-7.2.0}/src/xtr_maker/exception/target_exists_error.py +0 -0
  51. {xtr_maker-7.0.0 → xtr_maker-7.2.0}/src/xtr_maker/exception/unsafe_path_error.py +0 -0
  52. {xtr_maker-7.0.0 → xtr_maker-7.2.0}/src/xtr_maker/file_manager.py +0 -0
  53. {xtr_maker-7.0.0 → xtr_maker-7.2.0}/src/xtr_maker/generator.py +0 -0
  54. {xtr_maker-7.0.0 → xtr_maker-7.2.0}/src/xtr_maker/import_collector.py +0 -0
  55. {xtr_maker-7.0.0 → xtr_maker-7.2.0}/src/xtr_maker/name_converter.py +0 -0
  56. {xtr_maker-7.0.0 → xtr_maker-7.2.0}/src/xtr_maker/py.typed +0 -0
  57. {xtr_maker-7.0.0 → xtr_maker-7.2.0}/src/xtr_maker/recipe/__init__.py +0 -0
  58. {xtr_maker-7.0.0 → xtr_maker-7.2.0}/src/xtr_maker/recipe/manifest.toml +0 -0
  59. {xtr_maker-7.0.0 → xtr_maker-7.2.0}/src/xtr_maker/template_renderer.py +0 -0
  60. {xtr_maker-7.0.0 → xtr_maker-7.2.0}/src/xtr_maker/templates/command/command.py.jinja +0 -0
  61. {xtr_maker-7.0.0 → xtr_maker-7.2.0}/src/xtr_maker/templates/entity/association_table.py.jinja +0 -0
  62. {xtr_maker-7.0.0 → xtr_maker-7.2.0}/src/xtr_maker/templates/entity/entity.py.jinja +0 -0
  63. {xtr_maker-7.0.0 → xtr_maker-7.2.0}/src/xtr_maker/templates/entity/repository.py.jinja +0 -0
  64. {xtr_maker-7.0.0 → xtr_maker-7.2.0}/src/xtr_maker/templates/listener/event_listener.py.jinja +0 -0
  65. {xtr_maker-7.0.0 → xtr_maker-7.2.0}/src/xtr_maker/templates/listener/event_subscriber.py.jinja +0 -0
  66. {xtr_maker-7.0.0 → xtr_maker-7.2.0}/src/xtr_maker/templates/message/message.py.jinja +0 -0
  67. {xtr_maker-7.0.0 → xtr_maker-7.2.0}/src/xtr_maker/templates/message/message_handler.py.jinja +0 -0
  68. {xtr_maker-7.0.0 → xtr_maker-7.2.0}/src/xtr_maker/templates/scheduler/schedule.py.jinja +0 -0
  69. {xtr_maker-7.0.0 → xtr_maker-7.2.0}/src/xtr_maker/templates/webhook/request_parser.py.jinja +0 -0
  70. {xtr_maker-7.0.0 → xtr_maker-7.2.0}/src/xtr_maker/templates/webhook/webhook_config.py.jinja +0 -0
  71. {xtr_maker-7.0.0 → xtr_maker-7.2.0}/src/xtr_maker/templates/webhook/webhook_consumer.py.jinja +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: xtr-maker
3
- Version: 7.0.0
3
+ Version: 7.2.0
4
4
  Summary: Console commands that write application code for the xtr libraries: messages, schedules, webhooks, entities, commands and listeners.
5
5
  Keywords: generator,scaffolding,code generation,console,templates
6
6
  Author: Xterr
@@ -77,6 +77,7 @@ uv add --dev "xtr-maker[messenger,scheduler,webhook,orm,event-dispatcher]"
77
77
  | [`make:command`](#makecommand) | A console command class | — (the console bundle alone) |
78
78
  | [`make:listener`](#makelistener) | A listener or a subscriber of one event | `event_dispatcher` |
79
79
  | [`make:migration`](#makemigration) | A revision of what the tables changed | `orm` |
80
+ | [`make:fixtures`](#makefixtures) | A fixture class seeding the database | `orm_fixtures` |
80
81
 
81
82
  `list make` shows the ones an application has. A maker whose bundle is not active is not
82
83
  registered at all: there is no command that tells you to install something.
@@ -99,6 +100,7 @@ class per module:
99
100
  | `command/` | `<snake>_command.py` | `make:command` |
100
101
  | `event_listener/` | `<snake>_listener.py` | `make:listener` |
101
102
  | `event_subscriber/` | `<snake>_subscriber.py` | `make:listener` |
103
+ | `fixtures/` | `<snake>.py` | `make:fixtures` |
102
104
 
103
105
  A name may carry a subpackage: `make:message ordering.PlaceOrder` writes
104
106
  `message/ordering/place_order.py`. A folder with no `__init__.py` gets one declaring nothing, so
@@ -390,6 +392,34 @@ Next:
390
392
  - Review the new revision, then run orm:migrations:migrate -n.
391
393
  ```
392
394
 
395
+ ## `make:fixtures`
396
+
397
+ ```
398
+ make:fixtures [name]
399
+ ```
400
+
401
+ Writes a class built on [xtr-orm-fixtures](../xtr-orm-fixtures)'s `Fixture`, with an empty
402
+ `load(session)` to fill with the objects it seeds. The fixtures bundle finds a fixture wherever it
403
+ is, so `fixtures/` is only where the maker puts it.
404
+
405
+ - The name gets `Fixtures` at its end unless it has it: `books` writes `BooksFixtures`. Asked when
406
+ left out, offering `AppFixtures`; without a terminal it must be given.
407
+ - `catalog.BookFixtures` writes `fixtures/catalog/book_fixtures.py`.
408
+ - Listed when the fixtures bundle is active, which is in `dev` and `test`. xtr-orm-fixtures is
409
+ never an extra here: it is a development dependency of the application itself.
410
+
411
+ ```sh
412
+ $ uv run app make:fixtures AppFixtures -n
413
+ created: src/app/fixtures/__init__.py
414
+ created: src/app/fixtures/app_fixtures.py
415
+
416
+ [OK] Wrote AppFixtures.
417
+
418
+ Next:
419
+ - Open src/app/fixtures/app_fixtures.py and add the objects it seeds.
420
+ - Load them with orm:fixtures:load.
421
+ ```
422
+
393
423
  ## What every maker does, and never does
394
424
 
395
425
  - **Nothing is overwritten.** A target that exists, or one another file of the same run already
@@ -47,6 +47,7 @@ uv add --dev "xtr-maker[messenger,scheduler,webhook,orm,event-dispatcher]"
47
47
  | [`make:command`](#makecommand) | A console command class | — (the console bundle alone) |
48
48
  | [`make:listener`](#makelistener) | A listener or a subscriber of one event | `event_dispatcher` |
49
49
  | [`make:migration`](#makemigration) | A revision of what the tables changed | `orm` |
50
+ | [`make:fixtures`](#makefixtures) | A fixture class seeding the database | `orm_fixtures` |
50
51
 
51
52
  `list make` shows the ones an application has. A maker whose bundle is not active is not
52
53
  registered at all: there is no command that tells you to install something.
@@ -69,6 +70,7 @@ class per module:
69
70
  | `command/` | `<snake>_command.py` | `make:command` |
70
71
  | `event_listener/` | `<snake>_listener.py` | `make:listener` |
71
72
  | `event_subscriber/` | `<snake>_subscriber.py` | `make:listener` |
73
+ | `fixtures/` | `<snake>.py` | `make:fixtures` |
72
74
 
73
75
  A name may carry a subpackage: `make:message ordering.PlaceOrder` writes
74
76
  `message/ordering/place_order.py`. A folder with no `__init__.py` gets one declaring nothing, so
@@ -360,6 +362,34 @@ Next:
360
362
  - Review the new revision, then run orm:migrations:migrate -n.
361
363
  ```
362
364
 
365
+ ## `make:fixtures`
366
+
367
+ ```
368
+ make:fixtures [name]
369
+ ```
370
+
371
+ Writes a class built on [xtr-orm-fixtures](../xtr-orm-fixtures)'s `Fixture`, with an empty
372
+ `load(session)` to fill with the objects it seeds. The fixtures bundle finds a fixture wherever it
373
+ is, so `fixtures/` is only where the maker puts it.
374
+
375
+ - The name gets `Fixtures` at its end unless it has it: `books` writes `BooksFixtures`. Asked when
376
+ left out, offering `AppFixtures`; without a terminal it must be given.
377
+ - `catalog.BookFixtures` writes `fixtures/catalog/book_fixtures.py`.
378
+ - Listed when the fixtures bundle is active, which is in `dev` and `test`. xtr-orm-fixtures is
379
+ never an extra here: it is a development dependency of the application itself.
380
+
381
+ ```sh
382
+ $ uv run app make:fixtures AppFixtures -n
383
+ created: src/app/fixtures/__init__.py
384
+ created: src/app/fixtures/app_fixtures.py
385
+
386
+ [OK] Wrote AppFixtures.
387
+
388
+ Next:
389
+ - Open src/app/fixtures/app_fixtures.py and add the objects it seeds.
390
+ - Load them with orm:fixtures:load.
391
+ ```
392
+
363
393
  ## What every maker does, and never does
364
394
 
365
395
  - **Nothing is overwritten.** A target that exists, or one another file of the same run already
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "xtr-maker"
3
- version = "7.0.0"
3
+ version = "7.2.0"
4
4
  description = "Console commands that write application code for the xtr libraries: messages, schedules, webhooks, entities, commands and listeners."
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.14.4"
@@ -54,6 +54,7 @@ dev = [
54
54
  "xtr-event-dispatcher>=7.0,<8",
55
55
  "xtr-messenger>=7.0,<8",
56
56
  "xtr-orm[sqlite]>=7.0,<8",
57
+ "xtr-orm-fixtures>=7.0,<8",
57
58
  "xtr-scheduler>=7.0,<8",
58
59
  "xtr-webhook>=7.0,<8",
59
60
  "xtr-cache>=7.0,<8",
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "xtr-maker"
3
- version = "7.0.0"
3
+ version = "7.2.0"
4
4
  description = "Console commands that write application code for the xtr libraries: messages, schedules, webhooks, entities, commands and listeners."
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.14.4"
@@ -54,6 +54,8 @@ dev = [
54
54
  "xtr-messenger>=7.0,<8",
55
55
  # With its SQLite driver: the entity and migration makers' tests use a SQLite database.
56
56
  "xtr-orm[sqlite]>=7.0,<8",
57
+ # Development-only, so never an extra: make:fixtures writes code for it, importing nothing.
58
+ "xtr-orm-fixtures>=7.0,<8",
57
59
  "xtr-scheduler>=7.0,<8",
58
60
  "xtr-webhook>=7.0,<8",
59
61
  # The bundles make:schedule's --stateful and --lock need active.
@@ -20,6 +20,7 @@ written outside the project, and no secret is ever generated.
20
20
  | `make:command [name] [--argument A]... [--option O]...` | `command/<snake>_command.py` | — |
21
21
  | `make:listener [name] [event]` | `event_listener/<snake>_listener.py` or `event_subscriber/<snake>_subscriber.py` | `event_dispatcher` |
22
22
  | `make:migration [--message M] [--connection C]` | a revision in the connection's migrations directory | `orm` |
23
+ | `make:fixtures [name]` | `fixtures/<snake>.py`, a `Fixture` with an empty `load` | `orm_fixtures` |
23
24
 
24
25
  - Anything left off the command line is asked; `-n` asks nothing and takes the defaults, but the
25
26
  name always has to be given.
@@ -108,6 +109,16 @@ Compares the connection's database with its table definitions and lets its migra
108
109
  revision, as `orm:migrations:diff` does. Every revision must be applied first, or the run fails
109
110
  with `Run orm:migrations:migrate -n first.` Nothing differing writes nothing and still succeeds.
110
111
 
112
+ ## A fixture
113
+
114
+ ```sh
115
+ uv run app make:fixtures catalog.BookFixtures -n
116
+ ```
117
+
118
+ Writes `fixtures/catalog/book_fixtures.py`: a `Fixture` subclass whose `load(session)` adds what
119
+ it seeds. A name without `Fixtures` at its end gets it. Then fill `load` and run
120
+ `orm:fixtures:load` — see the `xtr-orm-fixtures` skill.
121
+
111
122
  ## Testing
112
123
 
113
124
  - Generated code is ordinary application code: test it the way the application tests the rest.
@@ -42,6 +42,7 @@ _MAKERS: Final[tuple[tuple[str, str | None], ...]] = (
42
42
  ("xtr_maker.command.make_command_command", None),
43
43
  ("xtr_maker.command.make_listener_command", "event_dispatcher"),
44
44
  ("xtr_maker.command.make_migration_command", "orm"),
45
+ ("xtr_maker.command.make_fixtures_command", "orm_fixtures"),
45
46
  )
46
47
  """Each maker's command module, and the bundle that must be active for it (``None``: none)."""
47
48
 
@@ -0,0 +1,122 @@
1
+ """``make:fixtures``: a fixture class seeding the application's database."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from typing import Final, final
6
+
7
+ from xtr_console import ConsoleStyle, ExitCode, as_command, escape
8
+ from xtr_dependency_injection import ( # noqa: TC002 — the console reads annotations at runtime.
9
+ Injected,
10
+ )
11
+
12
+ from xtr_maker.class_name import ClassName
13
+ from xtr_maker.exception import InvalidArgumentError, InvalidClassNameError, TargetExistsError
14
+ from xtr_maker.file_manager import ( # noqa: TC001 — the container reads annotations at runtime.
15
+ FileManager,
16
+ )
17
+ from xtr_maker.generator import Generator # noqa: TC001 — the console reads annotations at runtime.
18
+ from xtr_maker.import_collector import ImportCollector
19
+
20
+ __all__ = ["MakeFixturesCommand"]
21
+
22
+ _DEFAULT_NAME: Final = "AppFixtures"
23
+ """The name offered when asked: a first fixture class, before there are several."""
24
+
25
+ _ATTEMPTS: Final = 3
26
+ """How many times the name is asked: an input that has ended answers empty every time."""
27
+
28
+ _TEMPLATE: Final = "fixtures/fixtures.py.jinja"
29
+
30
+
31
+ @final
32
+ @as_command("make:fixtures", description="Write a fixture class that seeds the database.")
33
+ class MakeFixturesCommand:
34
+ """Writes ``fixtures/<name>.py``: a fixture class with an empty ``load``.
35
+
36
+ The fixtures bundle finds it wherever it is, so the folder is only where
37
+ makers put it; ``catalog.BookFixtures`` writes ``fixtures/catalog/``. The
38
+ name is asked when left out, ``AppFixtures`` offered; without a terminal
39
+ (``-n``) it must be given.
40
+ """
41
+
42
+ __slots__ = ("_file_manager",)
43
+
44
+ def __init__(self, file_manager: FileManager) -> None:
45
+ """Write into the package ``file_manager`` holds.
46
+
47
+ Args:
48
+ file_manager: The application package the class is written into.
49
+ """
50
+ self._file_manager = file_manager
51
+
52
+ async def __call__(
53
+ self,
54
+ io: ConsoleStyle,
55
+ generator: Injected[Generator],
56
+ name: str | None = None,
57
+ ) -> int:
58
+ """Write a fixture class.
59
+
60
+ Args:
61
+ io: Where the command writes, and asks.
62
+ generator: What writes the file.
63
+ name: The fixture's class name, such as ``AppFixtures`` or ``books``;
64
+ ``catalog.BookFixtures`` writes it under ``fixtures/catalog/``.
65
+ """
66
+ try:
67
+ fixture = self._fixture_name(io, name)
68
+ except (InvalidArgumentError, InvalidClassNameError) as error:
69
+ io.error(escape(str(error)))
70
+ return ExitCode.INVALID
71
+ try:
72
+ path = generator.generate_class(fixture, _TEMPLATE, _context(fixture, generator))
73
+ except TargetExistsError as error:
74
+ io.error(escape(str(error)))
75
+ return ExitCode.FAILURE
76
+ generator.write_changes(io)
77
+ io.success(f"Wrote {fixture.short_name}.")
78
+ io.text("Next:")
79
+ io.text(
80
+ f" - Open {escape(self._file_manager.relative(path))} and add the objects it seeds."
81
+ )
82
+ io.text(" - Load them with orm:fixtures:load.")
83
+ return ExitCode.SUCCESS
84
+
85
+ def _fixture_name(self, io: ConsoleStyle, typed: str | None) -> ClassName:
86
+ """Return the fixture class ``typed`` names, asking for it when it was left out.
87
+
88
+ Raises:
89
+ InvalidArgumentError: When no name was given and nothing may be asked.
90
+ InvalidClassNameError: When the name given cannot name a class, or
91
+ no answer could after the last attempt.
92
+ """
93
+ if typed is not None:
94
+ return self._fixture_class(typed)
95
+ if not io.interactive:
96
+ raise InvalidArgumentError(
97
+ "Name the fixture class to write: make:fixtures <name>, such as"
98
+ " make:fixtures AppFixtures."
99
+ )
100
+ question = "The fixture's class name"
101
+ for _ in range(_ATTEMPTS - 1):
102
+ try:
103
+ return self._fixture_class(io.ask(question, _DEFAULT_NAME))
104
+ except InvalidClassNameError as error:
105
+ io.error(escape(str(error)))
106
+ return self._fixture_class(io.ask(question, _DEFAULT_NAME))
107
+
108
+ def _fixture_class(self, typed: str) -> ClassName:
109
+ return ClassName.create(
110
+ typed, root_package=self._file_manager.root_package, kind="fixtures", suffix="Fixtures"
111
+ )
112
+
113
+
114
+ def _context(fixture: ClassName, generator: Generator) -> dict[str, object]:
115
+ """Return what the template reads: its imports, and the names it writes them under."""
116
+ imports = ImportCollector(fixture.root_package)
117
+ if generator.final_classes:
118
+ _ = imports.add("typing", "final")
119
+ override = imports.add("typing", "override")
120
+ session = imports.add("sqlalchemy.ext.asyncio", "AsyncSession", type_checking=True)
121
+ base = imports.add("xtr_orm_fixtures", "Fixture")
122
+ return {"imports": imports.render(), "override": override, "session": session, "base": base}
@@ -187,7 +187,8 @@ class EventRegistry:
187
187
  if package is None:
188
188
  return
189
189
  yield package
190
- path = cast("Sequence[str]", getattr(package, "__path__", ()))
190
+ # Read where the import system sets it: a module ``__getattr__`` may answer any name.
191
+ path = cast("Sequence[str]", vars(package).get("__path__", ()))
191
192
  for found in pkgutil.walk_packages(path, prefix=f"{package.__name__}."):
192
193
  module = _module(found.name)
193
194
  if module is not None:
@@ -0,0 +1,23 @@
1
+ """The data ``{{ class_name }}`` seeds the database with."""
2
+
3
+ from __future__ import annotations
4
+
5
+ {{ imports }}
6
+
7
+ __all__ = ["{{ class_name }}"]
8
+
9
+
10
+ {% if final_classes %}
11
+ @final
12
+ {% endif %}
13
+ class {{ class_name }}({{ base }}):
14
+ """Seeds the database; describe what it adds here."""
15
+
16
+ @{{ override }}
17
+ async def load(self, session: {{ session }}) -> None:
18
+ """Add this fixture's objects to ``session``; the run commits them.
19
+
20
+ ``session.add(book)`` adds one; ``self.add_reference("dune", book)``
21
+ hands it to the fixtures that depend on this one.
22
+ """
23
+ del session # Replace with the objects this fixture adds.
File without changes