Skip to content

Commit d954f84

Browse files
committed
chore: docs
1 parent deb98c9 commit d954f84

6 files changed

Lines changed: 98 additions & 19 deletions

File tree

pyproject.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,6 @@ line-length = 120
4444
lint.ignore = [
4545
"CPY001", # Missing copyright notice
4646
"D100", # Undocumented public module
47-
"D203", # One blank line required before class docstring (conflicts with D211)
48-
"D213", # Multi-line docstring summary should start at the second line (conflicts with D212)
4947
"PLC0415", # Import outside top level
5048
"PLR0911", # Too many return statements
5149
]

src/Litestar/generator.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from pathlib import Path
44

55
from jinja2 import Environment
6+
67
from src.models import DatabaseConfig, ProjectConfig
78
from src.utils import get_package_dir, get_template_env, write_file
89

@@ -23,7 +24,12 @@ def __init__(self, config: ProjectConfig, output_dir: Path) -> None:
2324
self.litestar_dir = get_package_dir() / "Litestar"
2425

2526
def _get_template_context(self) -> dict:
26-
"""Build the template context."""
27+
"""Build the template context.
28+
29+
Returns:
30+
The template context dictionary.
31+
32+
"""
2733
db_config = DatabaseConfig.for_database(self.config.database)
2834

2935
return {

src/cli.py

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,12 @@ def print_banner() -> None:
2323

2424

2525
def ask_project_name() -> str:
26-
"""Ask for the project name."""
26+
"""Ask for the project name.
27+
28+
Returns:
29+
The validated project name.
30+
31+
"""
2732
while True:
2833
name = questionary.text(
2934
"What is your project name?",
@@ -43,7 +48,12 @@ def ask_project_name() -> str:
4348

4449

4550
def ask_framework() -> Framework:
46-
"""Ask for the backend framework."""
51+
"""Ask for the backend framework.
52+
53+
Returns:
54+
The selected framework.
55+
56+
"""
4757
choices = [
4858
questionary.Choice(title="Litestar", value=Framework.LITESTAR),
4959
]
@@ -61,7 +71,12 @@ def ask_framework() -> Framework:
6171

6272

6373
def ask_database() -> Database:
64-
"""Ask for the database choice."""
74+
"""Ask for the database choice.
75+
76+
Returns:
77+
The selected database.
78+
79+
"""
6580
choices = [
6681
questionary.Choice(title="PostgreSQL", value=Database.POSTGRESQL),
6782
questionary.Choice(title="SQLite", value=Database.SQLITE),
@@ -82,7 +97,15 @@ def ask_database() -> Database:
8297

8398

8499
def ask_plugins(database: Database) -> list[Plugin]:
85-
"""Ask for plugins to install."""
100+
"""Ask for plugins to install.
101+
102+
Args:
103+
database: The selected database to determine plugin availability.
104+
105+
Returns:
106+
A list of selected plugins.
107+
108+
"""
86109
choices = []
87110

88111
# SQLAlchemy only makes sense with a database
@@ -111,7 +134,12 @@ def ask_plugins(database: Database) -> list[Plugin]:
111134

112135

113136
def ask_docker() -> tuple[bool, bool]:
114-
"""Ask for Docker configuration."""
137+
"""Ask for Docker configuration.
138+
139+
Returns:
140+
A tuple of (generate_dockerfile, generate_docker_infra).
141+
142+
"""
115143
docker = questionary.confirm(
116144
"Generate Dockerfile for the application?",
117145
default=False,

src/docs/ARCHITECTURE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ All templates use **Jinja2** with `.jinja` extension. Template context includes:
120120

121121
2. Add to `Plugin` enum in `models.py`:
122122
```python
123-
class Plugin(str, Enum):
123+
class Plugin(StrEnum):
124124
SQLALCHEMY = "SQLAlchemy"
125125
JWT = "JWT"
126126
NEW_PLUGIN = "NewPlugin" # Add this

src/models.py

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

3-
from enum import Enum
3+
from enum import StrEnum
44

55
import msgspec
66

77

8-
class Framework(str, Enum):
8+
class Framework(StrEnum):
99
"""Supported backend frameworks."""
1010

1111
LITESTAR = "Litestar"
1212

1313

14-
class Database(str, Enum):
14+
class Database(StrEnum):
1515
"""Supported database options."""
1616

1717
POSTGRESQL = "PostgreSQL"
@@ -20,7 +20,7 @@ class Database(str, Enum):
2020
NONE = "None"
2121

2222

23-
class Plugin(str, Enum):
23+
class Plugin(StrEnum):
2424
"""Available plugins."""
2525

2626
SQLALCHEMY = "SQLAlchemy"
@@ -68,7 +68,15 @@ class DatabaseConfig(msgspec.Struct):
6868

6969
@classmethod
7070
def for_database(cls, db: Database) -> "DatabaseConfig | None":
71-
"""Get configuration for a specific database."""
71+
"""Get configuration for a specific database.
72+
73+
Args:
74+
db: The database type.
75+
76+
Returns:
77+
The configuration for the specified database, or None if not found.
78+
79+
"""
7280
configs = {
7381
Database.POSTGRESQL: cls(
7482
driver="postgresql+asyncpg",

src/utils.py

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,25 @@
1010

1111

1212
def get_package_dir() -> Path:
13-
"""Get the package directory."""
13+
"""Get the package directory.
14+
15+
Returns:
16+
The path to the package directory.
17+
18+
"""
1419
return Path(__file__).parent
1520

1621

1722
def get_template_env(template_dir: Path) -> Environment:
18-
"""Create a Jinja2 environment for the given template directory."""
23+
"""Create a Jinja2 environment for the given template directory.
24+
25+
Args:
26+
template_dir: The directory containing the templates.
27+
28+
Returns:
29+
A configured Jinja2 environment.
30+
31+
"""
1932
return Environment(
2033
loader=FileSystemLoader(str(template_dir)),
2134
autoescape=select_autoescape(default=False),
@@ -26,7 +39,15 @@ def get_template_env(template_dir: Path) -> Environment:
2639

2740

2841
def slugify(text: str) -> str:
29-
"""Convert text to a valid Python package name."""
42+
"""Convert text to a valid Python package name.
43+
44+
Args:
45+
text: The text to slugify.
46+
47+
Returns:
48+
The slugified text.
49+
50+
"""
3051
# Convert to lowercase
3152
text = text.lower()
3253
# Replace spaces and hyphens with underscores
@@ -40,7 +61,15 @@ def slugify(text: str) -> str:
4061

4162

4263
def validate_project_name(name: str) -> str | None:
43-
"""Validate project name. Returns error message or None if valid."""
64+
"""Validate project name. Returns error message or None if valid.
65+
66+
Args:
67+
name: The project name to validate.
68+
69+
Returns:
70+
An error message if the name is invalid, otherwise None.
71+
72+
"""
4473
if not name:
4574
return "Project name cannot be empty"
4675
if len(name) < MIN_PROJECT_NAME_LENGTH:
@@ -66,6 +95,16 @@ def write_file(path: Path, content: str) -> None:
6695

6796

6897
def render_template(env: Environment, template_name: str, context: dict) -> str:
69-
"""Render a Jinja2 template with the given context."""
98+
"""Render a Jinja2 template with the given context.
99+
100+
Args:
101+
env: The Jinja2 environment.
102+
template_name: The name of the template to render.
103+
context: The context dictionary to render the template with.
104+
105+
Returns:
106+
The rendered template string.
107+
108+
"""
70109
template = env.get_template(template_name)
71110
return template.render(**context)

0 commit comments

Comments
 (0)