|
| 1 | +# AGENTS.md - AI Coding Agent Instructions |
| 2 | + |
| 3 | +Condensed instructions for AI agents. See [README.md](README.md) and [CONTRIBUTING.md](CONTRIBUTING.md) for full details. |
| 4 | + |
| 5 | +## Project Overview |
| 6 | + |
| 7 | +Python package (3.11+) providing repository configuration and scaffolding for Frequenz projects: cookiecutter templates (actor, api, app, lib, model), nox sessions, protobuf/gRPC utilities, MkDocs and pytest utilities. |
| 8 | + |
| 9 | +**Package:** `src/frequenz/repo/config/` (namespace package, `setuptools_scm` versioning) |
| 10 | + |
| 11 | +## Quick Reference |
| 12 | + |
| 13 | +```sh |
| 14 | +# Setup |
| 15 | +pip install -e .[dev] # All dev dependencies |
| 16 | +pip install -e .[dev-noxfile] # Just noxfile deps |
| 17 | + |
| 18 | +# Test |
| 19 | +nox -s pytest_max # Full test suite |
| 20 | +nox -R -s pytest_max # Reuse venv (faster) |
| 21 | +pytest tests/ # Direct pytest |
| 22 | +UPDATE_GOLDEN=1 pytest tests/integration/test_cookiecutter_generation.py::test_golden |
| 23 | + |
| 24 | +# Lint (run before committing) |
| 25 | +nox # All checks |
| 26 | +nox -s formatting # black + isort |
| 27 | +nox -s mypy # Type checking |
| 28 | +nox -R -s mypy # Reuse venv |
| 29 | +``` |
| 30 | + |
| 31 | +**Markers:** `integration`, `cookiecutter` |
| 32 | + |
| 33 | +## Project Structure |
| 34 | + |
| 35 | +``` |
| 36 | +src/frequenz/repo/config/ # Main package (_core.py, nox/, mkdocs/, pytest/, setuptools/, cli/) |
| 37 | +tests/ # Unit tests, tests/integration/ for integration tests |
| 38 | +tests_golden/ # Golden test fixtures |
| 39 | +cookiecutter/ # Cookiecutter templates |
| 40 | +``` |
| 41 | + |
| 42 | +## Code Patterns |
| 43 | + |
| 44 | +```python |
| 45 | +# File header (required) |
| 46 | +# License: MIT |
| 47 | +# Copyright © 2023 Frequenz Energy-as-a-Service GmbH |
| 48 | +"""Module docstring.""" |
| 49 | + |
| 50 | +import dataclasses |
| 51 | +from typing import Self, assert_never |
| 52 | + |
| 53 | +# Dataclasses: always kw_only + frozen if intended to be immutable |
| 54 | +@dataclasses.dataclass(kw_only=True, frozen=True) |
| 55 | +class Config: |
| 56 | + """Docstring.""" |
| 57 | + opts: CommandsOptions = dataclasses.field(default_factory=CommandsOptions) |
| 58 | + |
| 59 | +# Functions: strict typing, Google docstrings |
| 60 | +def func(session: _nox.Session, /, *, flag: bool = True) -> list[str]: |
| 61 | + """Brief description. |
| 62 | +
|
| 63 | + Args: |
| 64 | + session: The nox session. |
| 65 | + flag: Optional flag. |
| 66 | +
|
| 67 | + Returns: |
| 68 | + List of strings. |
| 69 | + """ |
| 70 | +``` |
| 71 | + |
| 72 | +| Type | Convention | Example | |
| 73 | +|------|------------|---------| |
| 74 | +| Files/functions | snake_case | `api_pages.py`, `find_dirs()` | |
| 75 | +| Classes | PascalCase | `RepositoryType` | |
| 76 | +| Constants | UPPER_SNAKE | `UPDATE_GOLDEN` | |
| 77 | +| Private | `_` prefix | `_impl()` | |
| 78 | + |
| 79 | +**Formatting:** black formatting using 4 spaces (Python), 2 spaces (YAML/TOML/JSON), 88 line length, 100 max, double quotes |
| 80 | + |
| 81 | +When changing files that are regularly reset (like `RELEASE_NOTES.md` or `cookiecutter/migrate.py`), consult the git history to match the style used in the past. |
| 82 | + |
| 83 | +## Commit Messages |
| 84 | +- Use imperative mood: "Add", "Fix", "Update" |
| 85 | +- Use a 50-character limit for the subject line (can go a bit over if necessary), and wrap body at 80 characters |
| 86 | +- Include a brief description of the change in the body if needed, focus on the what and why, and avoid describing how, especially if it is obvious from the code/diff |
| 87 | +- Separate changes into logical commits |
| 88 | +- Consult the recent git history, specifically of the files being committed, to match style and conventions in commit messages used previously. |
| 89 | + |
| 90 | +## Cookiecutter Template Changes |
| 91 | + |
| 92 | +See [CONTRIBUTING.md](CONTRIBUTING.md#modifying-cookiecutter-templates) for the full workflow. Summary: |
| 93 | + |
| 94 | +1. Edit templates in `cookiecutter/{{cookiecutter.github_repo_name}}/` |
| 95 | +2. Update golden files: `UPDATE_GOLDEN=1 pytest tests/integration/test_cookiecutter_generation.py::test_golden` |
| 96 | +3. Write migration in `cookiecutter/migrate.py` (idempotent; use `manual_step()` for non-automatable changes) |
| 97 | +4. Validate: `python3 cookiecutter/migrate.py && git diff .github/` |
| 98 | +5. Update `RELEASE_NOTES.md` |
| 99 | +6. Commit separately: templates first, then this repo's migration result |
0 commit comments