Repository navigation
Expand file tree
/
Copy pathcodegen.py
More file actions
66 lines (49 loc) · 1.9 KB
/
Copy pathcodegen.py
File metadata and controls
66 lines (49 loc) · 1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
"""Code generation commands (generate-stubs)."""
import typer
from oxyde.cli.app import app, load_config_or_exit
from oxyde.migrations.config import import_models
@app.command(name="generate-stubs")
def generate_stubs() -> None:
"""
Generate .pyi stub files for all registered table models.
Creates type stub files with autocomplete support for QuerySet filter/exclude
methods with all field lookups (contains, gt, gte, etc.).
"""
from oxyde.codegen import generate_stubs_for_models, write_stubs
from oxyde.models.registry import registered_tables
# Load config and import models
config = load_config_or_exit()
typer.echo("🔧 Generating type stubs...")
typer.echo()
# Import models first
imported = import_models(config.models)
if imported == 0:
typer.secho("❌ No modules imported", fg=typer.colors.RED)
raise typer.Exit(1)
try:
# Get all registered table models
models = list(registered_tables().values())
if not models:
typer.secho("⚠️ No table models found", fg=typer.colors.YELLOW)
typer.echo("Make sure your models have 'class Meta: is_table = True'")
return
typer.echo(f"Found {len(models)} table model(s):")
for model in models:
typer.echo(f" - {model.__module__}.{model.__name__}")
typer.echo()
typer.echo("Generating stubs...")
# Generate stubs
stub_mapping = generate_stubs_for_models(models)
# Write to disk
write_stubs(stub_mapping)
typer.echo()
typer.secho(
f"✅ Generated {len(stub_mapping)} stub file(s)",
fg=typer.colors.GREEN,
bold=True,
)
except Exception as e:
typer.secho(f"❌ Error generating stubs: {e}", fg=typer.colors.RED)
import traceback
traceback.print_exc()
raise typer.Exit(1)