|
| 1 | +# CLAUDE.md - Repository Development Guidelines |
| 2 | + |
| 3 | +This document contains the essential development patterns, tools, and best practices for this repository. **Read this first** to understand the codebase conventions and standards. |
| 4 | + |
| 5 | +## 🛠️ Core Development Stack |
| 6 | + |
| 7 | +### **Package Management: uv** |
| 8 | +- **Always use `uv`** instead of `pip` or `poetry` |
| 9 | +- Installation: `uv sync` (not `pip install -r requirements.txt`) |
| 10 | +- Running commands: `uv run <command>` (not direct command execution) |
| 11 | +- Add dependencies: `uv add <package>` (not `pip install`) |
| 12 | + |
| 13 | +```bash |
| 14 | +# ✅ Correct |
| 15 | +uv sync |
| 16 | +uv run pytest |
| 17 | +uv run mypy src/ |
| 18 | +uv add new-package |
| 19 | + |
| 20 | +# ❌ Incorrect |
| 21 | +pip install -r requirements.txt |
| 22 | +pytest |
| 23 | +mypy src/ |
| 24 | +pip install new-package |
| 25 | +``` |
| 26 | + |
| 27 | +### **Python Version: 3.13+** |
| 28 | +- **Minimum Python 3.13** required |
| 29 | +- Use modern Python features (match statements, improved type hints, etc.) |
| 30 | +- CLI commands: **Always use `python3`** (not `python`) |
| 31 | + |
| 32 | +```bash |
| 33 | +# ✅ Correct |
| 34 | +python3 -m venv .venv |
| 35 | +python3 script.py |
| 36 | + |
| 37 | +# ❌ Incorrect |
| 38 | +python -m venv .venv |
| 39 | +python script.py |
| 40 | +``` |
| 41 | + |
| 42 | +## 🔧 Code Quality Tools |
| 43 | + |
| 44 | +### **Linting: ruff** |
| 45 | +- **Primary linter and formatter**: ruff (not flake8, black, or isort) |
| 46 | +- Auto-fix enabled in configuration |
| 47 | +- Line length: 120 characters |
| 48 | +- Always fix linting issues before committing |
| 49 | + |
| 50 | +```bash |
| 51 | +# Format code |
| 52 | +uv run ruff format |
| 53 | + |
| 54 | +# Check and auto-fix issues |
| 55 | +uv run ruff check --fix |
| 56 | + |
| 57 | +# Check only (no fixes) |
| 58 | +uv run ruff check |
| 59 | +``` |
| 60 | + |
| 61 | +### **Type Checking: mypy** |
| 62 | +- **Strict typing enabled** |
| 63 | +- Type annotations required for all functions |
| 64 | +- `--strict` mode enabled in configuration |
| 65 | +- Source path: `src/` directory structure |
| 66 | + |
| 67 | +```bash |
| 68 | +# Type checking |
| 69 | +uv run mypy src/ |
| 70 | + |
| 71 | +# Check specific module |
| 72 | +uv run mypy src/module_name/ |
| 73 | +``` |
| 74 | + |
| 75 | +### **Testing: pytest** |
| 76 | +- **Test framework**: pytest with asyncio support |
| 77 | +- Coverage reporting enabled |
| 78 | +- Test directory: `tests/` |
| 79 | +- **Async tests**: Use pytest-asyncio (configured in `asyncio_mode = "auto"`) |
| 80 | + |
| 81 | +```bash |
| 82 | +# Run all tests |
| 83 | +uv run pytest |
| 84 | + |
| 85 | +# Run with coverage |
| 86 | +uv run pytest --cov=src |
| 87 | + |
| 88 | +# Run specific test file |
| 89 | +uv run pytest tests/test_specific.py |
| 90 | +``` |
| 91 | + |
| 92 | +## ⚡ Async Programming: anyio |
| 93 | + |
| 94 | +### **Use anyio (NOT asyncio)** |
| 95 | +- **Always import `anyio`** instead of `asyncio` |
| 96 | +- Task groups: `anyio.create_task_group()` (not `asyncio.gather()`) |
| 97 | +- Running async code: `anyio.run(main)` (not `asyncio.run(main())`) |
| 98 | +- Subprocess: `anyio.run_process()` (not `asyncio.create_subprocess_exec()`) |
| 99 | + |
| 100 | +```python |
| 101 | +# ✅ Correct |
| 102 | +import anyio |
| 103 | + |
| 104 | +async def main(): |
| 105 | + async with anyio.create_task_group() as tg: |
| 106 | + tg.start_task(task1) |
| 107 | + tg.start_task(task2) |
| 108 | + |
| 109 | +anyio.run(main) |
| 110 | + |
| 111 | +# ❌ Incorrect |
| 112 | +import asyncio |
| 113 | + |
| 114 | +async def main(): |
| 115 | + await asyncio.gather(task1(), task2()) |
| 116 | + |
| 117 | +asyncio.run(main()) |
| 118 | +``` |
| 119 | + |
| 120 | +### **Task Group Pattern** |
| 121 | +```python |
| 122 | +# Parallel execution with anyio |
| 123 | +async with anyio.create_task_group() as tg: |
| 124 | + for item in items: |
| 125 | + async def process_item(data=item): |
| 126 | + result = await process(data) |
| 127 | + results[data.id] = result |
| 128 | + |
| 129 | + tg.start_task(process_item) |
| 130 | +``` |
| 131 | + |
| 132 | +## 📁 Project Structure |
| 133 | + |
| 134 | +### **Source Directory**: `src/` |
| 135 | +- Main code in `src/package_name/` |
| 136 | +- Tests in `tests/` |
| 137 | +- Examples in `examples/` |
| 138 | +- Documentation in root or `docs/` |
| 139 | + |
| 140 | +### **Import Patterns** |
| 141 | +```python |
| 142 | +# ✅ Correct - absolute imports from src |
| 143 | +from package_name.module import Class |
| 144 | +from package_name.interfaces import Interface |
| 145 | + |
| 146 | +# ❌ Incorrect - relative imports in main code |
| 147 | +from .module import Class |
| 148 | +from ..interfaces import Interface |
| 149 | +``` |
| 150 | + |
| 151 | +## 🏗️ Development Workflow |
| 152 | + |
| 153 | +### **Setup New Environment** |
| 154 | +```bash |
| 155 | +git clone <repository> |
| 156 | +cd <repository> |
| 157 | +uv sync # Install dependencies |
| 158 | +uv run pytest # Run tests |
| 159 | +uv run ruff check # Check linting |
| 160 | +uv run mypy src/ # Type checking |
| 161 | +``` |
| 162 | + |
| 163 | +### **Pre-Commit Checklist** |
| 164 | +1. **Linting**: `uv run ruff check --fix` |
| 165 | +2. **Formatting**: `uv run ruff format` |
| 166 | +3. **Type checking**: `uv run mypy src/` |
| 167 | +4. **Tests**: `uv run pytest` |
| 168 | +5. **All checks passing**: Commit only when green |
| 169 | + |
| 170 | +### **Configuration Files** |
| 171 | +- `pyproject.toml` - Central configuration (dependencies, tools, build) |
| 172 | +- `README.md` - Project documentation and examples |
| 173 | +- `.env` - Environment variables (local, not committed) |
| 174 | +- `.gitignore` - Git ignore patterns |
| 175 | + |
| 176 | +## 🎯 Code Standards |
| 177 | + |
| 178 | +### **Type Annotations** |
| 179 | +- **Required for all functions** and methods |
| 180 | +- Use modern type hints (`list[str]` not `List[str]`) |
| 181 | +- Import types from `typing` when needed |
| 182 | +- Use `Any` sparingly, prefer specific types |
| 183 | + |
| 184 | +```python |
| 185 | +# ✅ Correct |
| 186 | +def process_data(items: list[dict[str, Any]]) -> tuple[bool, list[str]]: |
| 187 | + pass |
| 188 | + |
| 189 | +# ❌ Incorrect |
| 190 | +def process_data(items): |
| 191 | + pass |
| 192 | +``` |
| 193 | + |
| 194 | +### **Error Handling** |
| 195 | +- Use try/except blocks appropriately |
| 196 | +- Log errors with structured logging |
| 197 | +- Return meaningful error messages |
| 198 | +- Don't silence exceptions without good reason |
| 199 | + |
| 200 | +### **Documentation** |
| 201 | +- Docstrings for public functions and classes |
| 202 | +- Type hints serve as inline documentation |
| 203 | +- README.md with usage examples |
| 204 | +- Keep documentation up to date |
| 205 | + |
| 206 | +## 🔄 Common Commands Reference |
| 207 | + |
| 208 | +```bash |
| 209 | +# Development setup |
| 210 | +uv sync |
| 211 | + |
| 212 | +# Code quality |
| 213 | +uv run ruff format # Format code |
| 214 | +uv run ruff check --fix # Fix linting issues |
| 215 | +uv run mypy src/ # Type checking |
| 216 | + |
| 217 | +# Testing |
| 218 | +uv run pytest # Run all tests |
| 219 | +uv run pytest --cov=src # With coverage |
| 220 | +uv run pytest -v # Verbose output |
| 221 | + |
| 222 | +# Package management |
| 223 | +uv add package-name # Add dependency |
| 224 | +uv add --dev package-name # Add dev dependency |
| 225 | +uv remove package-name # Remove dependency |
| 226 | + |
| 227 | +# Running scripts |
| 228 | +uv run python3 script.py # Run Python script |
| 229 | +uv run python3 -m module # Run module |
| 230 | +``` |
| 231 | + |
| 232 | +## 📋 File Naming Conventions |
| 233 | + |
| 234 | +- **Python files**: `snake_case.py` |
| 235 | +- **Test files**: `test_*.py` or `*_test.py` |
| 236 | +- **Configuration**: `pyproject.toml`, `.env`, etc. |
| 237 | +- **Documentation**: `README.md`, `CHANGELOG.md`, etc. |
| 238 | + |
| 239 | +## 🚨 Common Pitfalls to Avoid |
| 240 | + |
| 241 | +1. **Don't use `asyncio`** - Always use `anyio` |
| 242 | +2. **Don't use `python`** - Always use `python3` |
| 243 | +3. **Don't skip type annotations** - Required for all functions |
| 244 | +4. **Don't ignore linting errors** - Fix before committing |
| 245 | +5. **Don't use relative imports** in main source code |
| 246 | +6. **Don't commit without running tests** - Always test first |
| 247 | +7. **Don't use `pip`** directly - Always use `uv` |
| 248 | + |
| 249 | +## 🎯 Project-Specific Notes |
| 250 | + |
| 251 | +- **License**: MIT (unless otherwise specified) |
| 252 | +- **Python Version**: 3.13+ minimum |
| 253 | +- **Async Library**: anyio (not asyncio) |
| 254 | +- **Package Manager**: uv (not pip/poetry) |
| 255 | +- **Linter**: ruff (not flake8/black) |
| 256 | +- **Type Checker**: mypy with strict mode |
| 257 | + |
| 258 | +## 📚 Additional Resources |
| 259 | + |
| 260 | +- [uv documentation](https://docs.astral.sh/uv/) |
| 261 | +- [ruff documentation](https://docs.astral.sh/ruff/) |
| 262 | +- [anyio documentation](https://anyio.readthedocs.io/) |
| 263 | +- [mypy documentation](https://mypy.readthedocs.io/) |
| 264 | +- [pytest documentation](https://docs.pytest.org/) |
| 265 | + |
| 266 | +--- |
| 267 | + |
| 268 | +**Note**: This document should be read by anyone working on the codebase. When in doubt, follow these patterns and tools. They ensure consistency, quality, and maintainability across the project. |
0 commit comments