model-generator-kit 0.1.0__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.
Files changed (68) hide show
  1. model_generator/__init__.py +6 -0
  2. model_generator/generate.py +1030 -0
  3. model_generator/generators/__init__.py +38 -0
  4. model_generator/generators/api.py +287 -0
  5. model_generator/generators/constraints.py +176 -0
  6. model_generator/generators/database.py +147 -0
  7. model_generator/generators/enums.py +88 -0
  8. model_generator/generators/infrastructure.py +679 -0
  9. model_generator/generators/migrations.py +146 -0
  10. model_generator/py.typed +0 -0
  11. model_generator/schema/model.schema.json +758 -0
  12. model_generator/stacks/python-fastapi/config.yaml +403 -0
  13. model_generator/stacks/python-fastapi/templates/_shared/_base.j2 +26 -0
  14. model_generator/stacks/python-fastapi/templates/_shared/_entity.j2 +48 -0
  15. model_generator/stacks/python-fastapi/templates/_shared/_examples.j2 +50 -0
  16. model_generator/stacks/python-fastapi/templates/_shared/_fields.j2 +48 -0
  17. model_generator/stacks/python-fastapi/templates/_shared/_tests.j2 +143 -0
  18. model_generator/stacks/python-fastapi/templates/api/init.py.j2 +55 -0
  19. model_generator/stacks/python-fastapi/templates/api/pagination.py.j2 +79 -0
  20. model_generator/stacks/python-fastapi/templates/api/request.py.j2 +448 -0
  21. model_generator/stacks/python-fastapi/templates/api/response.py.j2 +222 -0
  22. model_generator/stacks/python-fastapi/templates/api/route.py.j2 +507 -0
  23. model_generator/stacks/python-fastapi/templates/database/constraints.py.j2 +439 -0
  24. model_generator/stacks/python-fastapi/templates/database/enums.py.j2 +55 -0
  25. model_generator/stacks/python-fastapi/templates/database/factory.py.j2 +265 -0
  26. model_generator/stacks/python-fastapi/templates/database/init.py.j2 +37 -0
  27. model_generator/stacks/python-fastapi/templates/database/model.py.j2 +476 -0
  28. model_generator/stacks/python-fastapi/templates/infrastructure/auth_router.py.j2 +434 -0
  29. model_generator/stacks/python-fastapi/templates/infrastructure/base.py.j2 +16 -0
  30. model_generator/stacks/python-fastapi/templates/infrastructure/csrf.py.j2 +121 -0
  31. model_generator/stacks/python-fastapi/templates/infrastructure/database_init.py.j2 +12 -0
  32. model_generator/stacks/python-fastapi/templates/infrastructure/encrypted_bytes.py.j2 +62 -0
  33. model_generator/stacks/python-fastapi/templates/infrastructure/engine.py.j2 +51 -0
  34. model_generator/stacks/python-fastapi/templates/infrastructure/errors.py.j2 +74 -0
  35. model_generator/stacks/python-fastapi/templates/infrastructure/gitignore.j2 +48 -0
  36. model_generator/stacks/python-fastapi/templates/infrastructure/main.py.j2 +94 -0
  37. model_generator/stacks/python-fastapi/templates/infrastructure/pyproject.toml.j2 +92 -0
  38. model_generator/stacks/python-fastapi/templates/infrastructure/rate_limit.py.j2 +41 -0
  39. model_generator/stacks/python-fastapi/templates/infrastructure/types.py.j2 +94 -0
  40. model_generator/stacks/python-fastapi/templates/infrastructure/utils.py.j2 +50 -0
  41. model_generator/stacks/python-fastapi/templates/infrastructure/validators.py.j2 +126 -0
  42. model_generator/stacks/python-fastapi/templates/migrations/env.py.j2 +125 -0
  43. model_generator/stacks/python-fastapi/templates/migrations/ini.j2 +109 -0
  44. model_generator/stacks/python-fastapi/templates/migrations/script.py.mako.j2 +35 -0
  45. model_generator/stacks/python-fastapi/templates/tests/conftest_root.py.j2 +122 -0
  46. model_generator/stacks/python-fastapi/templates/tests/contract.py.j2 +1860 -0
  47. model_generator/utils/__init__.py +31 -0
  48. model_generator/utils/conftest_generator.py +683 -0
  49. model_generator/utils/constants.py +6 -0
  50. model_generator/utils/loaders.py +292 -0
  51. model_generator/utils/parser.py +129 -0
  52. model_generator/utils/quality.py +43 -0
  53. model_generator/utils/templates.py +128 -0
  54. model_generator/validate.py +219 -0
  55. model_generator/wizard/__init__.py +10 -0
  56. model_generator/wizard/actions/__init__.py +1 -0
  57. model_generator/wizard/actions/clean.py +55 -0
  58. model_generator/wizard/actions/generate.py +166 -0
  59. model_generator/wizard/actions/project_setup.py +142 -0
  60. model_generator/wizard/actions/test_runner.py +60 -0
  61. model_generator/wizard/menu.py +43 -0
  62. model_generator/wizard/prompts.py +80 -0
  63. model_generator_kit-0.1.0.dist-info/METADATA +143 -0
  64. model_generator_kit-0.1.0.dist-info/RECORD +68 -0
  65. model_generator_kit-0.1.0.dist-info/WHEEL +5 -0
  66. model_generator_kit-0.1.0.dist-info/entry_points.txt +3 -0
  67. model_generator_kit-0.1.0.dist-info/licenses/LICENSE +21 -0
  68. model_generator_kit-0.1.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,146 @@
1
+ """
2
+ Migration generation utilities (Alembic).
3
+ """
4
+
5
+ from pathlib import Path
6
+ from typing import Any
7
+
8
+ from jinja2 import Environment
9
+
10
+
11
+ def generate_migration_init(
12
+ model: dict[str, Any],
13
+ config: dict[str, Any],
14
+ env: Environment,
15
+ project_root: Path,
16
+ no_root_files: bool = False,
17
+ ) -> list[dict[str, Any]]:
18
+ """Initialize Alembic migration structure.
19
+
20
+ When ``no_root_files`` is set, the project-root ``alembic.ini`` is
21
+ suppressed while the in-tree alembic/ scaffolding (env.py,
22
+ script.py.mako, README, versions/.gitkeep) still emits — those live
23
+ inside the migrations directory, not at the project root.
24
+ """
25
+ outputs = []
26
+
27
+ migrations_dir = project_root / config["paths"].get("migrations", "alembic")
28
+ versions_dir = migrations_dir / "versions"
29
+
30
+ migrations_dir.mkdir(parents=True, exist_ok=True)
31
+ versions_dir.mkdir(parents=True, exist_ok=True)
32
+
33
+ # alembic.ini (bootstrap-only; don't overwrite adopter customizations)
34
+ if not no_root_files:
35
+ alembic_ini_path = project_root / "alembic.ini"
36
+ if not alembic_ini_path.exists():
37
+ template = env.get_template("migrations/ini.j2")
38
+ content = template.render(config=config)
39
+ outputs.append({"path": alembic_ini_path, "content": content})
40
+
41
+ # env.py
42
+ template = env.get_template("migrations/env.py.j2")
43
+ content = template.render(config=config)
44
+ outputs.append({"path": migrations_dir / "env.py", "content": content})
45
+
46
+ # script.py.mako
47
+ template = env.get_template("migrations/script.py.mako.j2")
48
+ content = template.render(config=config)
49
+ outputs.append({"path": migrations_dir / "script.py.mako", "content": content})
50
+
51
+ # README.md
52
+ outputs.append(
53
+ {
54
+ "path": migrations_dir / "README.md",
55
+ "content": _get_migration_readme(),
56
+ }
57
+ )
58
+
59
+ # .gitkeep
60
+ outputs.append({"path": versions_dir / ".gitkeep", "content": ""})
61
+
62
+ return outputs
63
+
64
+
65
+ def _get_migration_readme() -> str:
66
+ """Return README content for migrations directory."""
67
+ return """# Database Migrations
68
+
69
+ This directory contains database migration files managed by Alembic.
70
+
71
+ ## Usage
72
+
73
+ ### Create a new migration
74
+ ```bash
75
+ alembic revision --autogenerate -m "description of changes"
76
+ ```
77
+
78
+ ### Apply migrations
79
+ ```bash
80
+ alembic upgrade head
81
+ ```
82
+
83
+ ### Rollback migrations
84
+ ```bash
85
+ alembic downgrade -1
86
+ ```
87
+
88
+ ### View migration history
89
+ ```bash
90
+ alembic history
91
+ ```
92
+
93
+ ### View current revision
94
+ ```bash
95
+ alembic current
96
+ ```
97
+
98
+ ## Environment Variables
99
+
100
+ Set `DATABASE_URL` environment variable before running migrations:
101
+ ```bash
102
+ export DATABASE_URL="postgresql://user:pass@localhost/dbname"
103
+ alembic upgrade head
104
+ ```
105
+
106
+ ## Generated by model-generator
107
+ """
108
+
109
+
110
+ def generate_migration_autogen(
111
+ model: dict[str, Any], config: dict[str, Any], env: Environment, project_root: Path
112
+ ) -> dict[str, Any] | None:
113
+ """
114
+ Return instructions for running Alembic autogenerate.
115
+
116
+ This can't be run directly during generation as it requires DATABASE_URL.
117
+ """
118
+ alembic_ini = project_root / "alembic.ini"
119
+
120
+ if not alembic_ini.exists():
121
+ print(" ⚠️ Alembic not initialized. Run with --target migration-init first.")
122
+ return None
123
+
124
+ print(" Running alembic revision --autogenerate...")
125
+
126
+ return {
127
+ "info": (
128
+ "Migration autogeneration requires DATABASE_URL and should be run manually"
129
+ ),
130
+ "instructions": """
131
+ 📋 Migration autogeneration requires a running database.
132
+
133
+ Model-generator has created your SQLAlchemy models — to create the
134
+ corresponding Alembic migration, run these commands from your project root:
135
+
136
+ 1. Start your database (if not already running):
137
+ docker-compose up -d timescaledb # or: docker-compose up -d postgres
138
+
139
+ 2. Generate the migration:
140
+ export DATABASE_URL="postgresql://user:pass@localhost:5432/dbname"
141
+ alembic revision --autogenerate -m "initial schema"
142
+
143
+ 3. Apply it:
144
+ alembic upgrade head
145
+ """,
146
+ }
File without changes