-
Notifications
You must be signed in to change notification settings - Fork 1
Description
DevOps: Add Pre-Push Git Hook for Ruff Linting and Formatting
Summary
Implement a Git pre-push hook to automatically run ruff check and ruff format before code is pushed to the remote repository. This will catch linting and formatting issues earlier in the development workflow, preventing CI failures and maintaining code quality standards.
Background
Currently, the project has:
- ✅ Pre-commit hooks configured in
.pre-commit-config.yamlwith ruff - ✅ CI workflow (
.github/workflows/ci.yml) that runs ruff checks on push/PR - ✅ Ruff configuration in
pyproject.toml(line-length: 119, target: py310)
However, developers may bypass pre-commit hooks (e.g., git commit --no-verify) or not have them installed, leading to CI failures when code is pushed.
Objective
Add a pre-push hook that:
- Runs
ruff check --fixto catch and auto-fix linting issues - Runs
ruff format --checkto verify code formatting - Blocks the push if either check fails
- Provides clear error messages to guide developers
Proposed Implementation
Option 1: Extend pre-commit configuration (Recommended)
Add a pre-push stage to .pre-commit-config.yaml:
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.8.3
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
stages: [pre-commit, pre-push]
- id: ruff-format
args: [--check]
stages: [pre-commit, pre-push]Option 2: Custom Git hook script
Create .git/hooks/pre-push script (or use a tool like Husky for Node.js projects, though less common in Python).
Acceptance Criteria
- Pre-push hook is configured and documented
- Hook runs
ruff checkwith appropriate arguments - Hook runs
ruff format --checkto verify formatting - Hook prevents push if checks fail with clear error messages
- Documentation updated in
docs/contributing.mdwith setup instructions - README.md updated if necessary
- Tested on local development environment
Configuration Details
Use existing ruff configuration from pyproject.toml:
- Line length: 119
- Target version: Python 3.10
- Exclude:
third_party/ - Lint ignore:
E402
Documentation Updates Needed
Update docs/contributing.md section "Pre-commit Checks" to include:
# Install pre-commit hooks (including pre-push)
pre-commit install --hook-type pre-push
# Run pre-push checks manually
pre-commit run --hook-stage push --all-filesBenefits
- ✅ Catch formatting/linting issues before CI runs
- ✅ Reduce CI failures and iteration time
- ✅ Enforce code quality standards consistently
- ✅ Align with existing CI workflow checks
- ✅ Minimal developer friction (auto-fix when possible)
Related Files
.pre-commit-config.yaml- Main configuration filepyproject.toml- Ruff settings.github/workflows/ci.yml- CI checks to mirrordocs/contributing.md- Developer documentation
Priority
Medium - Improves developer experience and code quality, but not blocking current development.
Labels
devops, tooling, code-quality, developer-experience