Makefile Guide#
This project uses a Makefile to standardize common development tasks. All commands are executed using uv run to ensure they run within the correct virtual environment with proper dependencies.
Why Use Make?#
- Consistency: Everyone on the team uses the same commands
- Simplicity: Easy-to-remember shortcuts for complex commands
- CI/CD Integration: Same commands work locally and in CI/CD pipelines
- Documentation: Self-documenting via
make help
Available Commands#
Getting Help#
Shows all available commands with descriptions.
Installing Dependencies#
Installs all production and development dependencies using uv sync --all-groups.
Equivalent to:
Linting Code#
Runs flake8 linter on src/ and test/ directories to check for code quality issues.
Equivalent to:
What it checks: - PEP 8 style violations - Syntax errors - Unused imports - Undefined variables - Code complexity warnings
Formatting Code#
# Format code (modifies files)
make format
# Check formatting without modifying files
make format-check
Uses Black to format Python code with consistent style.
Equivalent to:
CI/CD uses format-check to ensure code is properly formatted before merging.
Running Tests#
Executes pytest test suite and optionally generates coverage reports.
Equivalent to:
uv run pytest test/ # Run tests
uv run coverage run -m pytest test/ # With coverage
uv run coverage report # Show coverage
uv run coverage html # Generate HTML report
Coverage reports: - Terminal: coverage report shows percentages - HTML: htmlcov/index.html provides detailed line-by-line coverage
Cleaning Up#
Removes Python cache files, test artifacts, and coverage reports.
Cleans: - __pycache__/ directories - .pytest_cache/ directories - .mypy_cache/ directories - *.pyc files - htmlcov/ and .coverage files
CI/CD Integration#
Our GitHub Actions workflow (.github/workflows/ci.yml) uses the same Makefile commands:
- name: Install dependencies
run: uv sync --all-groups
- name: Lint
run: make lint
- name: Format Check
run: make format-check
- name: Test
run: make test
This ensures identical behavior between local development and CI/CD pipelines.
Why uv run?#
All commands in the Makefile use uv run <command> instead of running commands directly. This ensures:
- Correct Environment: Commands run in the virtual environment managed by uv
- Proper Dependencies: All required packages are available
- Version Consistency: Uses exact versions from
uv.lock - No Activation Required: Don't need to manually activate virtual environment
Example#
# Without uv run (requires manual activation)
source .venv/bin/activate
flake8 src/ test/
deactivate
# With uv run (automatic)
uv run flake8 src/ test/
Common Workflows#
Before Committing Code#
Continuous Development#
Pull Request Review#
make install # Ensure dependencies are current
make format-check # Verify formatting
make lint # Check code quality
make test-coverage # Run tests with coverage
Customizing the Makefile#
The Makefile is located at the project root (Makefile). You can add custom targets:
Best practices: 1. Always use uv run for Python commands 2. Add .PHONY: declaration for non-file targets 3. Update help target with new command descriptions 4. Keep commands simple and focused
Troubleshooting#
"make: command not found"#
Install Make:
# Windows (via Chocolatey)
choco install make
# macOS
brew install make
# Linux (usually pre-installed)
sudo apt-get install make # Debian/Ubuntu
sudo yum install make # RHEL/CentOS
"uv: command not found"#
Install uv:
# Windows
powershell -c "irm https://astral.sh/uv/install.ps1 | iex"
# macOS/Linux
curl -LsSf https://astral.sh/uv/install.sh | sh
Then run make install to set up dependencies.
"No module named 'pytest'" (or similar)#
Dependencies not installed. Run:
Commands fail on Windows#
If using Git Bash or WSL, ensure paths use forward slashes. The Makefile uses Unix-style commands which work in Git Bash but may fail in CMD/PowerShell.
Solutions: - Use Git Bash (recommended for Windows) - Use WSL (Windows Subsystem for Linux) - Install Unix tools via Chocolatey: choco install gnuwin32-coreutils.install
Related Documentation#
- Dependency Management - Managing Python dependencies with uv
- CI/CD Workflow - GitHub Actions configuration
- pyproject.toml - Project dependencies and configuration