|
| 1 | +# AI Agent Guidelines |
| 2 | + |
| 3 | +This document provides guidance for AI agents and contributors working on the `py-app-dev` repository. |
| 4 | + |
| 5 | +## Project Overview |
| 6 | + |
| 7 | +**py-app-dev** is a Python library providing application development modules. The codebase follows modern Python practices with strict type checking and comprehensive testing. |
| 8 | + |
| 9 | +- **Package name**: `py-app-dev` |
| 10 | +- **Python version**: 3.10+ |
| 11 | +- **Package manager**: [uv](https://docs.astral.sh/uv/) |
| 12 | +- **Build backend**: Poetry |
| 13 | +- **CI/CD**: GitHub Actions with semantic-release |
| 14 | + |
| 15 | +## Repository Structure |
| 16 | + |
| 17 | +``` |
| 18 | +src/py_app_dev/ # Main source code |
| 19 | +├── core/ # Core modules (runnable, config, cmd_line, etc.) |
| 20 | +└── mvp/ # MVP pattern implementation |
| 21 | +tests/ # Test files (pytest) |
| 22 | +docs/ # Sphinx documentation |
| 23 | +examples/ # Example code |
| 24 | +``` |
| 25 | + |
| 26 | +## Development Workflow |
| 27 | + |
| 28 | +### Quick Start |
| 29 | + |
| 30 | +```bash |
| 31 | +# Install pypeline (one-time setup) |
| 32 | +pipx install pypeline-runner |
| 33 | + |
| 34 | +# Run the full development pipeline (venv, lint, test, docs) |
| 35 | +pypeline run |
| 36 | +``` |
| 37 | + |
| 38 | +### Running Individual Steps |
| 39 | + |
| 40 | +The `pypeline.yaml` defines the pipeline steps. Run specific steps using: |
| 41 | + |
| 42 | +```bash |
| 43 | +# Create/update virtual environment |
| 44 | +pypeline run --step CreateVEnv |
| 45 | + |
| 46 | +# Run pre-commit checks (ruff, mypy, codespell) |
| 47 | +pypeline run --step PreCommit |
| 48 | + |
| 49 | +# Run tests with coverage |
| 50 | +pypeline run --step PyTest |
| 51 | + |
| 52 | +# Build documentation |
| 53 | +pypeline run --step Docs |
| 54 | + |
| 55 | +# Run multiple specific steps |
| 56 | +pypeline run --step CreateVEnv --step PyTest |
| 57 | + |
| 58 | +# Run with specific Python version |
| 59 | +pypeline run --step CreateVEnv --step PyTest --input python_version=3.13 |
| 60 | +``` |
| 61 | + |
| 62 | +## Coding Guidelines |
| 63 | + |
| 64 | +- Always include full **type hints** (functions, methods, public attrs, constants). |
| 65 | +- Prefer **pythonic** constructs: context managers, `pathlib`, comprehensions when clear, `enumerate`, `zip`, early returns, no over-nesting. |
| 66 | +- Follow **SOLID**: single responsibility; prefer composition; program to interfaces (`Protocol`/ABC); inject dependencies. |
| 67 | +- **Naming**: descriptive `snake_case` vars/funcs, `PascalCase` classes, `UPPER_SNAKE_CASE` constants. Avoid single-letter identifiers (including `i`, `j`, `a`, `b`) except in tight math helpers. |
| 68 | +- Code should be **self-documenting**. Use docstrings only for public APIs or non-obvious rationale/constraints; avoid noisy inline comments. |
| 69 | +- Errors: raise specific exceptions; never `except:` bare; add actionable context. |
| 70 | +- Imports: no wildcard; group stdlib/third-party/local, keep modules small and cohesive. |
| 71 | +- Testability: pure functions where possible; pass dependencies, avoid globals/singletons. |
| 72 | +- tests: use `pytest`; keep the tests to a minimum; use parametrized tests when possible; do no add useless comments; the tests shall be self-explanatory. |
| 73 | +- pytest fixtures: use them to avoid code duplication; use `conftest.py` for shared fixtures. Use `tmp_path` in case of file system operations. |
| 74 | + |
| 75 | +## Code Quality Rules |
| 76 | + |
| 77 | +> [!IMPORTANT] |
| 78 | +> **Follow these professional coding standards in all code.** |
| 79 | +
|
| 80 | +1. **Import Placement**: ALL imports MUST be at the top of the file |
| 81 | + - NEVER import modules inside functions or methods |
| 82 | + - Group imports: standard library, third-party, local |
| 83 | + - Use alphabetical ordering within groups |
| 84 | + - This is basic professional Python development |
| 85 | + |
| 86 | +## Non-Negotiable Development Rules |
| 87 | + |
| 88 | +> [!CAUTION] |
| 89 | +> **These rules MUST be followed for all code changes. No exceptions.** |
| 90 | +
|
| 91 | +### Plan Before Implementation |
| 92 | + |
| 93 | +1. **Always Present a Plan First**: Before making ANY code changes: |
| 94 | + - Present a clear implementation plan describing WHAT will be changed and HOW |
| 95 | + - Wait for explicit user approval before proceeding with implementation |
| 96 | + - Never jump straight to coding, even for seemingly simple changes |
| 97 | + |
| 98 | +2. **Plan Contents Must Include**: |
| 99 | + - Files to be modified/created/deleted |
| 100 | + - Key changes in each file |
| 101 | + - Any design decisions or trade-offs |
| 102 | + - Testing approach |
| 103 | + |
| 104 | +3. **No Exceptions**: Even if the user has already discussed an approach, always confirm the plan before execution. The user must explicitly approve before any code is written. |
| 105 | + |
| 106 | +### Test-First Development |
| 107 | + |
| 108 | +1. **Write Tests Before Implementation**: For any new functionality or bug fix: |
| 109 | + - Write a **meaningful test** that demonstrates the desired behavior or exposes the bug |
| 110 | + - Then implement the code to make the test pass |
| 111 | + - Tests should be **self-explanatory** - clear test names and minimal comments |
| 112 | + |
| 113 | +2. **Quality Over Quantity**: |
| 114 | + - **Less is better**: Write only meaningful tests that add value |
| 115 | + - Avoid redundant or trivial tests that don't catch real issues |
| 116 | + - Each test should verify a specific behavior or edge case |
| 117 | + - Use parametrized tests to cover multiple scenarios efficiently |
| 118 | + |
| 119 | +3. **Test Coverage Philosophy**: |
| 120 | + - Focus on testing **behavior**, not implementation details |
| 121 | + - Critical paths and business logic MUST have tests |
| 122 | + - Trivial getters/setters don't need tests |
| 123 | + - Integration tests for step classes and pipeline interactions |
| 124 | + |
| 125 | +### Validation Requirements |
| 126 | + |
| 127 | +1. **Run Full Pipeline**: After making changes, **ALWAYS** run: |
| 128 | + |
| 129 | + ```bash |
| 130 | + pypeline run |
| 131 | + ``` |
| 132 | + |
| 133 | + This executes: |
| 134 | + - Virtual environment setup |
| 135 | + - Pre-commit hooks (linting, type checking) |
| 136 | + - All tests |
| 137 | + - Code quality checks |
| 138 | + |
| 139 | +2. **No Shortcuts**: Do not commit code that: |
| 140 | + - Bypasses tests |
| 141 | + - Fails linting or type checking |
| 142 | + - Breaks existing functionality |
| 143 | + - Lacks test coverage for critical functionality |
| 144 | + |
| 145 | +### Definition of Done |
| 146 | + |
| 147 | +1. **Acceptance Criteria**: Changes are NOT complete until: |
| 148 | + - `pypeline run` executes with **zero failures** |
| 149 | + - All pre-commit checks pass |
| 150 | + - New functionality has appropriate test coverage |
| 151 | + |
| 152 | +## Commit Message Format |
| 153 | + |
| 154 | +This repository uses [conventional commits](https://www.conventionalcommits.org). Format: |
| 155 | + |
| 156 | +``` |
| 157 | +<type>(<scope>): <description> |
| 158 | +``` |
| 159 | + |
| 160 | +Types: `feat`, `fix`, `docs`, `style`, `refactor`, `test`, `chore`, `ci` |
| 161 | + |
| 162 | +Example: `feat(core): add async runnable support` |
0 commit comments