Skip to content

Commit cac9fb9

Browse files
committed
feat: enhance project structure and update dependencies
- Introduced .editorconfig for consistent coding styles across files. - Updated pre-commit configuration to use ruff v0.14.8 and adjusted pytest command. - Enhanced AGENTS.md with additional guidelines on comments and naming conventions. - Refactored Makefile to streamline commands and updated the main application entry point. - Upgraded dependencies in pyproject.toml, including pydantic and ty. - Added initial application logic in src/templates_python and utility functions for settings management. - Created tests for logging configuration and main application execution. All changes aim to improve code quality, maintainability, and project usability.
1 parent 03bb012 commit cac9fb9

16 files changed

Lines changed: 286 additions & 212 deletions

File tree

.codex/commands/summarize.md

Lines changed: 0 additions & 80 deletions
This file was deleted.

.editorconfig

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
end_of_line = lf
6+
insert_final_newline = true
7+
trim_trailing_whitespace = true
8+
9+
[*.py]
10+
indent_style = space
11+
indent_size = 2
12+
max_line_length = 88
13+
14+
[*.{yml,yaml,toml,md}]
15+
indent_style = space
16+
indent_size = 2

.github/workflows/ci.yml

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
key: ${{ runner.os }}-uv-${{ hashFiles('uv.lock') }}
2020

2121
- name: Install uv
22-
uses: astral-sh/setup-uv@v3
22+
uses: astral-sh/setup-uv@v5
2323
with:
2424
version: "latest"
2525

@@ -34,6 +34,31 @@ jobs:
3434
- name: Run ruff format check
3535
run: uv run ruff format --check .
3636

37+
typecheck:
38+
runs-on: ubuntu-latest
39+
steps:
40+
- uses: actions/checkout@v4
41+
42+
- name: Cache uv
43+
uses: actions/cache@v4
44+
with:
45+
path: ~/.cache/uv
46+
key: ${{ runner.os }}-uv-${{ hashFiles('uv.lock') }}
47+
48+
- name: Install uv
49+
uses: astral-sh/setup-uv@v5
50+
with:
51+
version: "latest"
52+
53+
- name: Set up Python
54+
run: uv python install 3.13
55+
56+
- name: Install dependencies
57+
run: uv sync --extra dev
58+
59+
- name: Run ty type checker
60+
run: uv run ty check
61+
3762
test:
3863
runs-on: ubuntu-latest
3964
strategy:
@@ -50,7 +75,7 @@ jobs:
5075
key: ${{ runner.os }}-uv-${{ hashFiles('uv.lock') }}
5176

5277
- name: Install uv
53-
uses: astral-sh/setup-uv@v3
78+
uses: astral-sh/setup-uv@v5
5479
with:
5580
version: "latest"
5681

@@ -61,4 +86,4 @@ jobs:
6186
run: uv sync --extra dev
6287

6388
- name: Run tests
64-
run: uv run pytest --cov=main --cov=utils --cov-report=xml --cov-report=term-missing
89+
run: uv run pytest --cov-report=xml

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ repos:
1212
- id: check-docstring-first
1313

1414
- repo: https://github.com/astral-sh/ruff-pre-commit
15-
rev: v0.13.3
15+
rev: v0.14.8
1616
hooks:
1717
- id: ruff
1818
args: [--fix]
@@ -22,7 +22,7 @@ repos:
2222
hooks:
2323
- id: pytest-check
2424
name: pytest-check
25-
entry: bash -c "PYTHONPATH=. uv run pytest --co -q"
25+
entry: bash -c "uv run pytest --co -q"
2626
language: system
2727
pass_filenames: false
2828
always_run: true

AGENTS.md

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,24 @@ This document provides coding guidelines for AI agents working on this Python pr
1515
**Format**: 2-space indentation, single quotes, 88-character lines, `snake_case` variables/functions, `PascalCase` classes, boolean flags prefixed with `is_/has_/should_`. Pre-commit hooks ensure code quality on commit.
1616

1717
**Docstrings**:
18+
1819
- Use simple one-line docstrings for most functions - be concise and descriptive
1920
- Type hints replace Args/Returns documentation - don't duplicate what's in the signature
2021
- No Examples section - type hints + function name should be self-explanatory
2122
- Exception: Top-level user-facing APIs may include brief usage notes if necessary
2223
- Rationale: Modern Python with PEP 484 type hints makes verbose docstrings redundant
2324

25+
**Comments**:
26+
27+
- Avoid narrating the code; prefer clear names and small functions
28+
- Comments should explain *why* (tradeoffs, invariants, pitfalls), not *what*
29+
- Delete commented-out code instead of keeping it around
30+
31+
**Naming**:
32+
33+
- Prefer domain-specific, intention-revealing names over generic ones (`process`, `handle`, `manager`, `util`)
34+
- Keep public API names stable and unsurprising; avoid cleverness
35+
2436
## Architecture Principles
2537

2638
**Classes for state and lifecycle**, pure functions for transformations. Use classes when managing resources, coordinating operations, or defining interfaces.
@@ -32,6 +44,7 @@ This document provides coding guidelines for AI agents working on this Python pr
3244
**Factory functions**: Standalone functions (`get_backend()`, `resolve_config()`) that map configurations to implementations.
3345

3446
**Resource management**:
47+
3548
- Reference counting for expensive resources (connections, clients) with acquire/release semantics
3649
- Context managers (`__enter__`/`__exit__`) for automatic cleanup
3750
- Track ownership with boolean flags to avoid closing borrowed resources
@@ -44,7 +57,7 @@ This document provides coding guidelines for AI agents working on this Python pr
4457

4558
**Performance**: Use `@dataclass(slots=True)` for frequently-instantiated objects and `TypeVar` for type-safe generic protocols.
4659

47-
**Resilience**: Exponential backoff for network operations, graceful empty returns over exceptions, debug logging for key metrics.
60+
**Resilience**: Exponential backoff for network operations, graceful empty returns over exceptions, debug logging for key metrics. Keep error handling targeted (catch specific exceptions, add context, re-raise/convert).
4861

4962
## Best Practices
5063

@@ -55,20 +68,22 @@ This document provides coding guidelines for AI agents working on this Python pr
5568
- Pipeline pattern: chain transformations with clear inputs/outputs
5669
- No excessive error handling or low-value comments
5770

71+
## Code Quality Bar (What to Avoid)
72+
73+
When generating code, optimize for reviewability and long-term maintainability.
74+
75+
- **Unnecessary comments**: If a comment just restates the code, remove it and improve naming/structure instead
76+
- **Long docstrings**: Keep most docstrings to a single line; only expand when a public API truly needs usage notes
77+
- **Overly defensive code**: Don’t add “just in case” checks everywhere; validate at boundaries and trust validated data internally
78+
- **Broad `try/except`**: Avoid wrapping whole functions; don’t swallow exceptions; catch specific errors only to recover or add context
79+
- **Deep nesting**: Prefer guard clauses and extraction to keep indentation shallow (avoid multi-level `if/for/try`)
80+
- **Bad abstractions**: Don’t create classes/protocols/layers without clear value; avoid one-method wrappers and “framework-building”
81+
- **Vague naming**: Avoid generic verbs (`do`, `process`, `handle`) and generic buckets (`utils`, `helpers`) for core logic
82+
- **Weak typing / schemas**: Avoid `Any` and unstructured `dict[str, Any]` in core code; prefer Pydantic models (or narrow typed objects) with explicit fields and validation
83+
- **Noisy error handling**: Prefer a small number of well-placed domain exceptions over many `RuntimeError`/`ValueError` catch-alls
84+
5885
## Pydantic Commitment
5986

6087
- All interface models use Pydantic `BaseModel` (not dataclasses)
6188
- Validation, `.model_dump()`, JSON serialization built-in
6289
- Reserve `@dataclass(slots=True)` only for inner performance-critical helpers (graph traversal caches, etc.)
63-
64-
## Codex Commands
65-
66-
Conventions:
67-
- Any user message that **starts with** `!` is a command.
68-
- Be non-verbose. For commands, print a single status line (or a short block) on success/failure.
69-
- Use UTC timestamps. Touch only files inside this repo.
70-
- If a directory you need doesn’t exist, create it.
71-
72-
Commands:
73-
74-
- `!summarize [slug]`: Read `.codex/commands/summarize.md` for command instructions.

Makefile

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
.PHONY: help install install-dev setup pre-commit-install pre-commit-run lint format typecheck test clean lock-check run
2-
3-
export PYTHONPATH := .
42
VENV_DIR = .venv
53

64
help:
@@ -37,14 +35,14 @@ format:
3735
uv run ruff format .
3836

3937
typecheck: ## Run ty type checker
40-
uv run ty check
38+
uv run ty check
4139

4240
test: ## Run Pytest
4341
uv run pytest
4442

4543
clean: ## Remove caches & pyc files
4644
find . -type f -name "*.pyc" -delete
47-
find . -type d -name "pycache" -exec rm -rf {} +
45+
find . -type d -name "__pycache__" -exec rm -rf {} +
4846
find . -type d -name ".pytest_cache" -exec rm -rf {} +
4947
find . -type d -name ".ruff_cache" -exec rm -rf {} +
5048
rm -rf .pytest_cache .ruff_cache .mypy_cache .coverage
@@ -53,4 +51,4 @@ lock-check: ## Ensure uv.lock is up-to-date
5351
uv sync --locked --extra dev
5452

5553
run: ## Run the main application
56-
uv run python src/main.py
54+
uv run templates-python

README.md

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Python Boilerplate
22

3+
![CI](https://github.com/abpai/templates.python/actions/workflows/ci.yml/badge.svg)
4+
![Python 3.13+](https://img.shields.io/badge/python-3.13+-blue.svg)
5+
![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)
6+
37
This template is a **lean starting point** for Python projects that use:
48

59
- ✅ Ruff – formatting & linting
@@ -44,7 +48,7 @@ This template is a **lean starting point** for Python projects that use:
4448
make format && make lint && make test
4549
```
4650

47-
`src/main.py` is a minimal script with structured logging. Modify it to build your application.
51+
`src/templates_python/main.py` is a minimal entry point with structured logging. Modify it to build your application.
4852

4953
---
5054

@@ -66,7 +70,7 @@ This template is a **lean starting point** for Python projects that use:
6670

6771
## Environment Variables
6872

69-
`utils/settings.py` reads variables from a `.env` file or the environment.
73+
`src/templates_python/utils/settings.py` reads variables from a `.env` file or the environment.
7074

7175
| Variable | Default | Description |
7276
| ------------ | --------- | ----------------------------------- |
@@ -83,15 +87,16 @@ Only what you need, nothing more:
8387

8488
```
8589
├── src/
86-
│ └── main.py # Main application entry point
87-
├── utils/
88-
│ └── settings.py # Pydantic Settings helper
90+
│ └── templates_python/
91+
│ ├── main.py # Main application entry point
92+
│ └── utils/
93+
│ └── settings.py # Pydantic Settings helper
8994
├── tests/
90-
│ └── test_basic.py # Single sanity-check test
95+
│ └── test_settings.py # Settings validation tests
9196
├── Makefile # Workflow commands
9297
├── pyproject.toml # Project + dependency config
9398
├── uv.lock # Locked dependency versions
94-
└── .github/workflows/ # CI (lint + test)
99+
└── .github/workflows/ # CI (lint + typecheck + test)
95100
```
96101
97102
---
@@ -124,6 +129,27 @@ Configuration is in `pyproject.toml` under `[tool.ty]`.
124129

125130
---
126131

132+
## Code Style
133+
134+
This project uses **2-space indentation** and **single quotes** (configured in Ruff). While Python conventionally uses 4-space indentation, 2-space is a deliberate choice for more compact code. The formatter enforces this automatically.
135+
136+
Key style settings:
137+
- Indent: 2 spaces
138+
- Quotes: Single (`'`)
139+
- Line length: 88 characters
140+
141+
---
142+
143+
## First Things To Edit
144+
145+
When copying this template into a new project, update:
146+
147+
- `[project] name`, `description`, `authors`, and `version` in `pyproject.toml`
148+
- The import package name under `src/` (rename `templates_python/` to your project slug)
149+
- The CLI entry in `[project.scripts]`
150+
151+
---
152+
127153
## License
128154

129155
MIT

0 commit comments

Comments
 (0)