Code Standards
Ruff and ty enforce most of these rules automatically; run the checks in Task Automation with nox before opening a pull request.
General Guidelines
- Line length: Maximum 88 characters (see Ruff Configurations)
- Python version: The project supports Python 3.11+ (
requires-python); Ruff targets Python 3.14 - Import order: Automatically handled by Ruff
- Naming conventions:
- Classes:
PascalCase - Functions/variables:
snake_case - Constants:
UPPER_SNAKE_CASE - Private members:
_leading_underscore
- Classes:
Type Hints
All functions and methods must have type hints:
1 2 3 4 5 6 7 8 | |
Docstring
All public functions, classes, and modules must have docstring:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | |
Code Organization
- One class per file (unless closely related)
- Group related functions in modules
- Keep functions focused - Single Responsibility Principle
- Avoid deep nesting - Maximum 3-4 levels
- Extract complex logic into named functions
Testing
Coverage
- Minimum coverage: 75% (including branch coverage), enforced by
pytest.ini(see Test Configurations) - Target coverage: 100% for new code
Writing Tests
- Location: Put tests for
tools/<module>/intests/tools/test__<module>.py(e.g.tools/logger/→tests/tools/test__logger.py) - Naming: Use the
test__*.pypattern (double underscore); other files are not collected - Structure: One test file per module
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | |
Running Tests
1 2 3 4 5 6 7 8 9 | |
Best Practices
- Test one thing per test function
- Use descriptive names -
test_logger_handles_none_values - Arrange-Act-Assert pattern
- Cover edge cases - empty inputs, None, boundary values
- Test error conditions - expected exceptions
- Minimize mocking - Use real objects when possible
- Independent tests - No dependencies between tests
Documentation
Update the documentation when you add features or utilities, change public APIs or configuration, add environment variables, or change the development workflow.
- Each topic has exactly one source of truth under
docs/. Edit that page;README.md,CONTRIBUTING.md, andCLAUDE.mdonly link to it and must not copy its content. - Configuration pages include the real config files with
--8<-- "<path>"(snippets); do not paste config contents into a page. - When adding a utility to
tools/, add a page todocs/guides/tools/and list it under Available Modules and Package Structure indocs/guides/tools/index.md. - When adding a page, register it in the
navofmkdocs.ymland check it withuv run mkdocs build --strict. - Provide code examples and test them before committing.
Common Issues
Test Coverage Below 75%
Run uv run nox -s test, open htmlcov/index.html to find uncovered lines, and add tests for them.
Lint Errors
1 2 3 | |
If type errors persist, add type hints or use # type: ignore with a justification.
Pre-commit Hook Failures
Run uv run pre-commit run --all-files to see what failed. Formatting and trailing whitespace are fixed by the hooks; fix JSON / YAML / TOML syntax errors manually, then git add and commit again.
Merge Conflicts
1 2 3 4 5 6 7 8 | |
uv.lock Out of Sync
If CI fails with dependency resolution errors, run uv lock and commit the updated uv.lock.
Import Errors in Tests
If tests fail with ModuleNotFoundError, run uv sync and import from the package root (e.g. from tools.logger import Logger, not from logger import Logger).