File tree Expand file tree Collapse file tree 3 files changed +83
-0
lines changed
Expand file tree Collapse file tree 3 files changed +83
-0
lines changed Original file line number Diff line number Diff line change @@ -44,6 +44,9 @@ git remote add upstream https://github.com/python-wheel-build/fromager.git
4444
4545# 4. Create development environment
4646hatch env create
47+
48+ # 5. Install pre-commit hook (optional but recommended)
49+ ./scripts/setup-pre-commit-hook.sh
4750```
4851
4952### Contribution Workflow
@@ -72,6 +75,25 @@ git push origin feat/<short-description>
7275# 7. Create a pull request on GitHub
7376```
7477
78+ ### Pre-commit Hook (Recommended)
79+
80+ To ensure quality checks run automatically before each commit, install the pre-commit hook that runs both linting and mypy type checking:
81+
82+ ``` bash
83+ # Install the pre-commit hook (run once after cloning)
84+ ./scripts/setup-pre-commit-hook.sh
85+
86+ # The hook automatically runs before each commit:
87+ # - hatch run lint:check
88+ # - hatch run mypy:check
89+
90+ # If the hook fails, it will prevent the commit and show helpful messages
91+ # You can fix issues automatically with:
92+ hatch run lint:fix
93+ ```
94+
95+ The pre-commit hook prevents commits that would fail CI quality checks, saving time and ensuring consistent code quality.
96+
7597---
7698
7799## Coding Standards
Original file line number Diff line number Diff line change 1+ #! /usr/bin/env bash
2+ #
3+ # Git pre-commit hook to run quality checks
4+ # This ensures all commits pass linting and type checking
5+ #
6+
7+ set -e # Exit immediately if any command fails
8+
9+ echo " Running pre-commit checks..."
10+
11+ # Run lint check
12+ echo " 🔍 Running lint check..."
13+ if ! hatch run lint:check; then
14+ echo " ❌ Lint check failed. Please fix linting issues and try again."
15+ echo " You can run 'hatch run lint:fix' to automatically fix many issues."
16+ exit 1
17+ fi
18+
19+ # Run mypy type checking
20+ echo " 🔍 Running mypy type check..."
21+ if ! hatch run mypy:check; then
22+ echo " ❌ MyPy type check failed. Please fix type annotations and try again."
23+ exit 1
24+ fi
25+
26+ echo " ✅ All pre-commit checks passed!"
Original file line number Diff line number Diff line change 1+ #! /usr/bin/env bash
2+ #
3+ # Setup script to install the pre-commit hook for fromager development
4+ #
5+ # This script copies the pre-commit hook to .git/hooks/ and makes it executable
6+ #
7+
8+ set -e
9+
10+ SCRIPT_DIR=" $( cd " $( dirname " ${BASH_SOURCE[0]} " ) " && pwd) "
11+ REPO_ROOT=" $( cd " $SCRIPT_DIR /.." && pwd) "
12+ HOOKS_DIR=" $REPO_ROOT /.git/hooks"
13+ PRE_COMMIT_HOOK=" $HOOKS_DIR /pre-commit"
14+
15+ echo " 🔧 Setting up pre-commit hook for fromager..."
16+
17+ # Check if we're in a git repository
18+ if [ ! -d " $HOOKS_DIR " ]; then
19+ echo " ❌ Error: Not in a git repository or .git/hooks directory not found"
20+ exit 1
21+ fi
22+
23+ # Copy the pre-commit hook script
24+ cp " $SCRIPT_DIR /pre-commit" " $PRE_COMMIT_HOOK "
25+
26+ # Make it executable
27+ chmod +x " $PRE_COMMIT_HOOK "
28+
29+ echo " ✅ Pre-commit hook installed successfully!"
30+ echo " "
31+ echo " The hook will now run 'hatch run lint:check' and 'hatch run mypy:check'"
32+ echo " before every commit to ensure code quality."
33+ echo " "
34+ echo " To bypass the hook for a specific commit (not recommended):"
35+ echo " git commit --no-verify -m \" message\" "
You can’t perform that action at this time.
0 commit comments