Skip to content

Commit ccc7170

Browse files
committed
chore: add ty
1 parent d954f84 commit ccc7170

7 files changed

Lines changed: 75 additions & 113 deletions

File tree

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Litestar Start - Architecture Documentation
1+
# Litestar Start
22

33
This document explains the architecture and design of `litestar-start`, a CLI tool for scaffolding Litestar projects.
44

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ lint:
44
@echo "Running linters... 🔄"
55
pre-commit install
66
pre-commit run -a
7+
ty check
78
@echo "Linters completed. ✅"
89

910
release:

pyproject.toml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@ classifiers = [
66
"Intended Audience :: Developers",
77
"License :: OSI Approved :: MIT License",
88
"Programming Language :: Python :: 3",
9-
"Programming Language :: Python :: 3.10",
10-
"Programming Language :: Python :: 3.11",
11-
"Programming Language :: Python :: 3.12",
129
"Programming Language :: Python :: 3.13",
1310
"Topic :: Software Development :: Code Generators",
1411
]
@@ -18,7 +15,7 @@ keywords = ["litestar", "scaffolding", "cli", "fullstack", "template", "generato
1815
license = "MIT"
1916
name = "litestar-start"
2017
readme = "README.md"
21-
requires-python = ">=3.10"
18+
requires-python = ">=3.13"
2219
version = "0.1.0a6"
2320

2421
[project.scripts]
@@ -49,4 +46,4 @@ lint.ignore = [
4946
]
5047

5148
[dependency-groups]
52-
dev = ["pre-commit>=4.5.1", "ruff>=0.14.11"]
49+
dev = ["pre-commit>=4.5.1", "ruff>=0.14.11", "ty>=0.0.11"]

src/cli.py

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
"""Command-line interface for litestar-start."""
22

3-
import sys
43
from pathlib import Path
54

65
import questionary
@@ -28,6 +27,9 @@ def ask_project_name() -> str:
2827
Returns:
2928
The validated project name.
3029
30+
Raises:
31+
SystemExit: If the user cancels the operation.
32+
3133
"""
3234
while True:
3335
name = questionary.text(
@@ -37,7 +39,7 @@ def ask_project_name() -> str:
3739

3840
if name is None: # User pressed Ctrl+C
3941
console.print("\n[yellow]Cancelled.[/yellow]")
40-
sys.exit(0)
42+
raise SystemExit(0)
4143

4244
error = validate_project_name(name)
4345
if error:
@@ -53,6 +55,9 @@ def ask_framework() -> Framework:
5355
Returns:
5456
The selected framework.
5557
58+
Raises:
59+
SystemExit: If the user cancels the operation.
60+
5661
"""
5762
choices = [
5863
questionary.Choice(title="Litestar", value=Framework.LITESTAR),
@@ -65,7 +70,7 @@ def ask_framework() -> Framework:
6570

6671
if result is None:
6772
console.print("\n[yellow]Cancelled.[/yellow]")
68-
sys.exit(0)
73+
raise SystemExit(0)
6974

7075
return result
7176

@@ -76,6 +81,9 @@ def ask_database() -> Database:
7681
Returns:
7782
The selected database.
7883
84+
Raises:
85+
SystemExit: If the user cancels the operation.
86+
7987
"""
8088
choices = [
8189
questionary.Choice(title="PostgreSQL", value=Database.POSTGRESQL),
@@ -91,7 +99,7 @@ def ask_database() -> Database:
9199

92100
if result is None:
93101
console.print("\n[yellow]Cancelled.[/yellow]")
94-
sys.exit(0)
102+
raise SystemExit(0)
95103

96104
return result
97105

@@ -105,6 +113,9 @@ def ask_plugins(database: Database) -> list[Plugin]:
105113
Returns:
106114
A list of selected plugins.
107115
116+
Raises:
117+
SystemExit: If the user cancels the operation.
118+
108119
"""
109120
choices = []
110121

@@ -127,7 +138,7 @@ def ask_plugins(database: Database) -> list[Plugin]:
127138

128139
if result is None:
129140
console.print("\n[yellow]Cancelled.[/yellow]")
130-
sys.exit(0)
141+
raise SystemExit(0)
131142

132143
# Filter out None values
133144
return [p for p in result if p is not None]
@@ -139,6 +150,9 @@ def ask_docker() -> tuple[bool, bool]:
139150
Returns:
140151
A tuple of (generate_dockerfile, generate_docker_infra).
141152
153+
Raises:
154+
SystemExit: If the user cancels the operation (e.g., presses Ctrl+C).
155+
142156
"""
143157
docker = questionary.confirm(
144158
"Generate Dockerfile for the application?",
@@ -147,7 +161,7 @@ def ask_docker() -> tuple[bool, bool]:
147161

148162
if docker is None:
149163
console.print("\n[yellow]Cancelled.[/yellow]")
150-
sys.exit(0)
164+
raise SystemExit(0)
151165

152166
docker_infra = questionary.confirm(
153167
"Generate docker-compose.infra.yml for local development (database, etc.)?",
@@ -156,13 +170,18 @@ def ask_docker() -> tuple[bool, bool]:
156170

157171
if docker_infra is None:
158172
console.print("\n[yellow]Cancelled.[/yellow]")
159-
sys.exit(0)
173+
raise SystemExit(0)
160174

161175
return docker, docker_infra
162176

163177

164178
def main() -> None:
165-
"""Run the main CLI interface."""
179+
"""Run the main CLI interface.
180+
181+
Raises:
182+
SystemExit: If the user cancels the operation (e.g., presses Ctrl+C).
183+
184+
"""
166185
print_banner()
167186

168187
try:
@@ -202,7 +221,7 @@ def main() -> None:
202221
proceed = questionary.confirm("Generate project?", default=True).ask()
203222
if not proceed:
204223
console.print("[yellow]Cancelled.[/yellow]")
205-
sys.exit(0)
224+
raise SystemExit(0)
206225

207226
# Generate project
208227
output_dir = Path.cwd() / config.slug
@@ -224,7 +243,7 @@ def main() -> None:
224243

225244
except KeyboardInterrupt:
226245
console.print("\n[yellow]Cancelled.[/yellow]")
227-
sys.exit(0)
246+
return
228247

229248

230249
if __name__ == "__main__":

src/models.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
"""Data models for project configuration."""
22

3+
from __future__ import annotations
4+
35
from enum import StrEnum
46

57
import msgspec
@@ -67,7 +69,7 @@ class DatabaseConfig(msgspec.Struct):
6769
docker_image: str | None = None
6870

6971
@classmethod
70-
def for_database(cls, db: Database) -> "DatabaseConfig | None":
72+
def for_database(cls, db: Database) -> DatabaseConfig | None:
7173
"""Get configuration for a specific database.
7274
7375
Args:

tools/prepare_release.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
"""Prepare a new release by bumping version numbers."""
33

44
import re
5-
import sys
65
from enum import StrEnum
76
from pathlib import Path
87

@@ -28,12 +27,16 @@ def get_current_version(pyproject_path: Path) -> str:
2827
Returns:
2928
Current version string.
3029
30+
Raises:
31+
SystemExit: If version cannot be found in pyproject.toml.
32+
3133
"""
3234
content = pyproject_path.read_text(encoding="utf-8")
3335
match = re.search(r'version = "(\d+\.\d+\.\d+(?:[ab]\d+)?)"', content)
3436
if not match:
3537
console.print("[red]Could not find version in pyproject.toml[/red]")
36-
sys.exit(1)
38+
raise SystemExit(1)
39+
3740
return match.group(1)
3841

3942

@@ -43,12 +46,15 @@ def bump_version(current_version: str, bump_type: BumpType) -> str:
4346
Returns:
4447
New version string.
4548
49+
Raises:
50+
SystemExit: If the version format is invalid.
51+
4652
"""
4753
# Parse version with optional alpha/beta suffix
4854
base_match = re.match(r"(\d+)\.(\d+)\.(\d+)(?:([ab])(\d+))?", current_version)
4955
if not base_match:
5056
console.print(f"[red]Invalid version format: {current_version}[/red]")
51-
sys.exit(1)
57+
raise SystemExit(1)
5258

5359
major = int(base_match.group(1))
5460
minor = int(base_match.group(2))
@@ -95,13 +101,18 @@ def update_file(path: Path, pattern: str, replacement: str) -> None:
95101

96102

97103
def main() -> None:
98-
"""Execute the release preparation process."""
104+
"""Execute the release preparation process.
105+
106+
Raises:
107+
SystemExit: If pyproject.toml is not found or version cannot be determined.
108+
109+
"""
99110
root_dir = Path(__file__).parent.parent
100111
pyproject_path = root_dir / "pyproject.toml"
101112

102113
if not pyproject_path.exists():
103114
console.print("[red]Could not find pyproject.toml.[/red]")
104-
sys.exit(1)
115+
raise SystemExit(1)
105116

106117
current_version = get_current_version(pyproject_path)
107118
console.print(f"Current version: [bold cyan]{current_version}[/bold cyan]")

0 commit comments

Comments
 (0)