Pre-commit hooks ensure code quality by running checks before each commit. This prevents broken or poorly formatted code from entering the repository.
Run the automated setup script:
python .github/scripts/setup-precommit.py
This will automatically install all required dependencies and configure the hooks.
If the automated script fails, follow these manual steps:
# Core testing framework
pip install pytest pytest-cov pytest-mock pytest-benchmark
# Performance monitoring
pip install psutil memory-profiler
# Security and cryptography
pip install pynacl pbr cryptography bandit safety
# Code quality tools
pip install flake8 black isort
# Testing utilities
pip install responses requests-mock
# Pre-commit framework
pip install pre-commit
# Install PowerTraderAI+ dependencies
pip install -r app/requirements.txt
python -m pre_commit install
# Run hooks on all files to test
python -m pre_commit run --all-files
The pre-commit system runs these checks before each commit:
| Package | Purpose | Required For |
|---|---|---|
pytest |
Testing framework | Running test suite |
pytest-cov |
Coverage reporting | Test coverage analysis |
pytest-mock |
Mocking utilities | Unit test mocking |
pytest-benchmark |
Performance testing | Benchmark tests |
psutil |
System monitoring | Performance tests |
memory-profiler |
Memory analysis | Memory usage tests |
pynacl |
Cryptography | Encryption/security features |
pbr |
Build utilities | Package building |
cryptography |
Cryptographic operations | Security features |
bandit |
Security scanner | Security vulnerability detection |
safety |
Dependency security | Package vulnerability scanning |
flake8 |
Code linter | Code quality checks |
black |
Code formatter | Automatic code formatting |
isort |
Import sorter | Import organization |
responses |
HTTP mocking | API testing |
requests-mock |
Request mocking | HTTP request testing |
If commits are blocked by hook failures:
git commit --no-verify (not recommended)If you get import errors during commit:
# Reinstall all dependencies
python .github/scripts/setup-precommit.py
# Or install manually
pip install pytest pytest-cov pytest-mock pytest-benchmark psutil memory-profiler pynacl pbr cryptography bandit safety flake8 black isort responses requests-mock
On Windows, if you get permission errors:
pip install --user [package]For isolated dependency management:
# Create virtual environment
python -m venv .venv
# Activate (Windows)
.venv\Scripts\activate
# Activate (Linux/Mac)
source .venv/bin/activate
# Install dependencies
python .github/scripts/setup-precommit.py
Pre-commit hooks complement the CI/CD pipeline:
This three-tier system ensures maximum code quality and reliability.