This document describes how to set up the development environment and use code quality tools.
# Install core dependencies
pip install -r requirements.txt
# Or install with dev dependencies (if using pyproject.toml)
pip install -e ".[dev]"This project uses several tools to maintain code quality:
- Ruff: Fast Python linter and formatter (replaces Black, flake8, isort, etc.)
- MyPy: Static type checker
Ruff is configured via ruff.toml. It combines the functionality of multiple linters (flake8, isort, Black, etc.) and is used for both linting and formatting.
# Check for issues
ruff check .
# Auto-fix issues
ruff check --fix .
# Format code
ruff format .
# Check formatting without making changes
ruff format --check .MyPy is configured via .mypy.ini and pyproject.toml.
# Type check
mypy email_processorPre-commit hooks automatically run code quality checks before each commit. It is required to run pre-commit checks before committing and pushing.
# Install pre-commit
pip install pre-commit
# Install git hooks (optional - hooks will run automatically on commit)
pre-commit install
# Run hooks manually (REQUIRED before commit and push)
pre-commit run --all-filesNote: Even if hooks are installed, always run pre-commit run --all-files manually before committing to ensure all checks pass.
# Run all tests
pytest
# Run with coverage
pytest --cov=email_processor --cov-report=html
# Run specific test file
pytest tests/unit/imap/test_fetcher_header.py
# Run all fetcher tests
pytest tests/unit/imap/test_fetcher_*.py
# Run specific test category
pytest tests/unit/imap/test_fetcher_attachment.py-
Check formatting (required):
ruff format --check .If files need formatting, run:
ruff format . -
Run pre-commit checks (required):
pre-commit run --all-files
This will run all hooks including:
- Trailing whitespace check
- End of file fixer
- Ruff linting and formatting
- Ruff check (full project check)
- MyPy type checking
-
Lint code (if pre-commit didn't fix everything):
ruff check --fix . -
Type check (optional, also runs in pre-commit):
mypy email_processor
-
Run tests:
pytest
Recommended workflow:
# 1. Check formatting first
ruff format --check .
# 2. If needed, format code
ruff format .
# 3. Run all pre-commit checks
pre-commit run --all-files
# 4. Run tests
pytest
# 5. Only then commit and push
git add .
git commit -m "your message"
git pushAdd to .vscode/settings.json:
{
"python.linting.enabled": true,
"python.linting.ruffEnabled": true,
"editor.formatOnSave": true,
"[python]": {
"editor.defaultFormatter": "charliermarsh.ruff",
"editor.codeActionsOnSave": {
"source.organizeImports": true,
"source.fixAll": true
}
}
}- Install Ruff plugin
- Configure Ruff as formatter and linter
- Enable MyPy inspection
ruff.toml- Ruff linter and formatter configurationpyproject.toml- MyPy and project metadata.mypy.ini- MyPy type checker configuration.pre-commit-config.yaml- Pre-commit hooks configurationpytest.ini- Pytest test configuration
- Line length: 100 characters
- Target Python version: 3.9+
- Type hints: Recommended but not required
- Docstrings: Use Google style for public APIs
Follow conventional commits format:
feat:New featurefix:Bug fixdocs:Documentation changesstyle:Code style changes (formatting, etc.)refactor:Code refactoringtest:Test additions/changeschore:Maintenance tasks
Example:
feat: add request ID and correlation ID to logs
fix: improve error handling with specific exceptions