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.
- model_generator/__init__.py +6 -0
- model_generator/generate.py +1030 -0
- model_generator/generators/__init__.py +38 -0
- model_generator/generators/api.py +287 -0
- model_generator/generators/constraints.py +176 -0
- model_generator/generators/database.py +147 -0
- model_generator/generators/enums.py +88 -0
- model_generator/generators/infrastructure.py +679 -0
- model_generator/generators/migrations.py +146 -0
- model_generator/py.typed +0 -0
- model_generator/schema/model.schema.json +758 -0
- model_generator/stacks/python-fastapi/config.yaml +403 -0
- model_generator/stacks/python-fastapi/templates/_shared/_base.j2 +26 -0
- model_generator/stacks/python-fastapi/templates/_shared/_entity.j2 +48 -0
- model_generator/stacks/python-fastapi/templates/_shared/_examples.j2 +50 -0
- model_generator/stacks/python-fastapi/templates/_shared/_fields.j2 +48 -0
- model_generator/stacks/python-fastapi/templates/_shared/_tests.j2 +143 -0
- model_generator/stacks/python-fastapi/templates/api/init.py.j2 +55 -0
- model_generator/stacks/python-fastapi/templates/api/pagination.py.j2 +79 -0
- model_generator/stacks/python-fastapi/templates/api/request.py.j2 +448 -0
- model_generator/stacks/python-fastapi/templates/api/response.py.j2 +222 -0
- model_generator/stacks/python-fastapi/templates/api/route.py.j2 +507 -0
- model_generator/stacks/python-fastapi/templates/database/constraints.py.j2 +439 -0
- model_generator/stacks/python-fastapi/templates/database/enums.py.j2 +55 -0
- model_generator/stacks/python-fastapi/templates/database/factory.py.j2 +265 -0
- model_generator/stacks/python-fastapi/templates/database/init.py.j2 +37 -0
- model_generator/stacks/python-fastapi/templates/database/model.py.j2 +476 -0
- model_generator/stacks/python-fastapi/templates/infrastructure/auth_router.py.j2 +434 -0
- model_generator/stacks/python-fastapi/templates/infrastructure/base.py.j2 +16 -0
- model_generator/stacks/python-fastapi/templates/infrastructure/csrf.py.j2 +121 -0
- model_generator/stacks/python-fastapi/templates/infrastructure/database_init.py.j2 +12 -0
- model_generator/stacks/python-fastapi/templates/infrastructure/encrypted_bytes.py.j2 +62 -0
- model_generator/stacks/python-fastapi/templates/infrastructure/engine.py.j2 +51 -0
- model_generator/stacks/python-fastapi/templates/infrastructure/errors.py.j2 +74 -0
- model_generator/stacks/python-fastapi/templates/infrastructure/gitignore.j2 +48 -0
- model_generator/stacks/python-fastapi/templates/infrastructure/main.py.j2 +94 -0
- model_generator/stacks/python-fastapi/templates/infrastructure/pyproject.toml.j2 +92 -0
- model_generator/stacks/python-fastapi/templates/infrastructure/rate_limit.py.j2 +41 -0
- model_generator/stacks/python-fastapi/templates/infrastructure/types.py.j2 +94 -0
- model_generator/stacks/python-fastapi/templates/infrastructure/utils.py.j2 +50 -0
- model_generator/stacks/python-fastapi/templates/infrastructure/validators.py.j2 +126 -0
- model_generator/stacks/python-fastapi/templates/migrations/env.py.j2 +125 -0
- model_generator/stacks/python-fastapi/templates/migrations/ini.j2 +109 -0
- model_generator/stacks/python-fastapi/templates/migrations/script.py.mako.j2 +35 -0
- model_generator/stacks/python-fastapi/templates/tests/conftest_root.py.j2 +122 -0
- model_generator/stacks/python-fastapi/templates/tests/contract.py.j2 +1860 -0
- model_generator/utils/__init__.py +31 -0
- model_generator/utils/conftest_generator.py +683 -0
- model_generator/utils/constants.py +6 -0
- model_generator/utils/loaders.py +292 -0
- model_generator/utils/parser.py +129 -0
- model_generator/utils/quality.py +43 -0
- model_generator/utils/templates.py +128 -0
- model_generator/validate.py +219 -0
- model_generator/wizard/__init__.py +10 -0
- model_generator/wizard/actions/__init__.py +1 -0
- model_generator/wizard/actions/clean.py +55 -0
- model_generator/wizard/actions/generate.py +166 -0
- model_generator/wizard/actions/project_setup.py +142 -0
- model_generator/wizard/actions/test_runner.py +60 -0
- model_generator/wizard/menu.py +43 -0
- model_generator/wizard/prompts.py +80 -0
- model_generator_kit-0.1.0.dist-info/METADATA +143 -0
- model_generator_kit-0.1.0.dist-info/RECORD +68 -0
- model_generator_kit-0.1.0.dist-info/WHEEL +5 -0
- model_generator_kit-0.1.0.dist-info/entry_points.txt +3 -0
- model_generator_kit-0.1.0.dist-info/licenses/LICENSE +21 -0
- model_generator_kit-0.1.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Enum generation utilities.
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
import re
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
from typing import Any
|
|
8
|
+
|
|
9
|
+
from jinja2 import Environment
|
|
10
|
+
|
|
11
|
+
from ..utils.loaders import load_shared_enums
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def get_existing_enums(enums_file: Path) -> set[str]:
|
|
15
|
+
"""Parse existing enums.py to find defined enum names."""
|
|
16
|
+
if not enums_file.exists():
|
|
17
|
+
return set()
|
|
18
|
+
|
|
19
|
+
content = enums_file.read_text()
|
|
20
|
+
pattern = r"class\s+(\w+)\s*\(\s*(?:str\s*,\s*Enum|StrEnum)\s*\)"
|
|
21
|
+
return set(re.findall(pattern, content))
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def generate_enums(
|
|
25
|
+
model: dict[str, Any],
|
|
26
|
+
config: dict[str, Any],
|
|
27
|
+
env: Environment,
|
|
28
|
+
project_root: Path,
|
|
29
|
+
model_path: Path,
|
|
30
|
+
) -> dict[str, Any] | None:
|
|
31
|
+
"""
|
|
32
|
+
Generate enum definitions from _shared/enums.json.
|
|
33
|
+
|
|
34
|
+
Creates file if missing, appends new enums if file exists.
|
|
35
|
+
"""
|
|
36
|
+
enum_defs = load_shared_enums(model_path)
|
|
37
|
+
|
|
38
|
+
if not enum_defs:
|
|
39
|
+
print(" ℹ️ No enums found in models/_shared/enums.json")
|
|
40
|
+
return None
|
|
41
|
+
|
|
42
|
+
output_dir = project_root / config["paths"]["database_models"]
|
|
43
|
+
enums_file = output_dir / "enums.py"
|
|
44
|
+
file_exists = enums_file.exists()
|
|
45
|
+
|
|
46
|
+
if file_exists:
|
|
47
|
+
existing_enums = get_existing_enums(enums_file)
|
|
48
|
+
new_enums = {
|
|
49
|
+
name: definition
|
|
50
|
+
for name, definition in enum_defs.items()
|
|
51
|
+
if name not in existing_enums
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if not new_enums:
|
|
55
|
+
print(f" ℹ️ All enums already exist in {enums_file}")
|
|
56
|
+
return None
|
|
57
|
+
|
|
58
|
+
template = env.get_template("database/enums.py.j2")
|
|
59
|
+
content = template.render(
|
|
60
|
+
mode="append",
|
|
61
|
+
section_header="ENUMS",
|
|
62
|
+
enums=new_enums,
|
|
63
|
+
config=config,
|
|
64
|
+
)
|
|
65
|
+
|
|
66
|
+
return {
|
|
67
|
+
"path": enums_file,
|
|
68
|
+
"content": "\n" + content,
|
|
69
|
+
"mode": "append",
|
|
70
|
+
"new_count": len(new_enums),
|
|
71
|
+
"skipped": len(enum_defs) - len(new_enums),
|
|
72
|
+
}
|
|
73
|
+
else:
|
|
74
|
+
template = env.get_template("database/enums.py.j2")
|
|
75
|
+
content = template.render(
|
|
76
|
+
mode="create",
|
|
77
|
+
section_header="ENUMS",
|
|
78
|
+
enums=enum_defs,
|
|
79
|
+
config=config,
|
|
80
|
+
)
|
|
81
|
+
|
|
82
|
+
return {
|
|
83
|
+
"path": enums_file,
|
|
84
|
+
"content": content,
|
|
85
|
+
"mode": "write",
|
|
86
|
+
"new_count": len(enum_defs),
|
|
87
|
+
"skipped": 0,
|
|
88
|
+
}
|