Skip to content

Commit 865d478

Browse files
codebydivineclaude
andcommitted
feat: Add pre-commit hooks for code quality enforcement
- Add .pre-commit-config.yaml with ruff linter/formatter and mypy - Add setup-pre-commit.sh script for easy installation - Update pyproject.toml dev dependencies with pre-commit tools - Fix pytest-anyio -> pytest-asyncio dependency name - Add missing newline at end of pyproject.toml This ensures all code is automatically formatted and linted on every commit, maintaining consistent code quality across the project. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent 2bdb2a3 commit 865d478

File tree

4 files changed

+102
-2
lines changed

4 files changed

+102
-2
lines changed

.pre-commit-config.yaml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# See https://pre-commit.com for more information
2+
repos:
3+
- repo: https://github.com/astral-sh/ruff-pre-commit
4+
rev: v0.8.4
5+
hooks:
6+
# Run the linter
7+
- id: ruff
8+
args: [--fix]
9+
# Run the formatter
10+
- id: ruff-format
11+
12+
- repo: https://github.com/pre-commit/pre-commit-hooks
13+
rev: v5.0.0
14+
hooks:
15+
- id: trailing-whitespace
16+
- id: end-of-file-fixer
17+
- id: check-yaml
18+
- id: check-added-large-files
19+
- id: check-json
20+
- id: check-toml
21+
- id: check-merge-conflict
22+
- id: debug-statements
23+
language_version: python3.13
24+
25+
- repo: https://github.com/pre-commit/mirrors-mypy
26+
rev: v1.14.1
27+
hooks:
28+
- id: mypy
29+
additional_dependencies: [types-requests]
30+
args: [--ignore-missing-imports]
31+
files: ^src/

pyproject.toml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,11 @@ dependencies = [
3535
dev = [
3636
"pytest>=8.0",
3737
"pytest-cov>=4.0",
38-
"pytest-anyio>=0.21",
38+
"pytest-asyncio>=0.21",
3939
"python-dotenv>=1.0.0",
40+
"pre-commit>=3.5.0",
41+
"ruff>=0.8.0",
42+
"mypy>=1.14.0",
4043
]
4144

4245
[project.urls]
@@ -90,4 +93,4 @@ python_version = "3.13"
9093
warn_return_any = true
9194
warn_unused_configs = true
9295
disallow_untyped_defs = false
93-
ignore_missing_imports = true
96+
ignore_missing_imports = true

scripts/setup-hooks.sh

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/bin/bash
2+
# Setup script for pre-commit hooks
3+
4+
echo "🔧 Setting up pre-commit hooks for code formatting..."
5+
6+
# Install pre-commit if in virtual environment
7+
if [[ "$VIRTUAL_ENV" != "" ]]; then
8+
echo "✓ Virtual environment detected"
9+
else
10+
echo "⚠️ No virtual environment detected. It's recommended to use one."
11+
echo " Run: python3 -m venv .venv && source .venv/bin/activate"
12+
read -p "Continue anyway? (y/N) " -n 1 -r
13+
echo
14+
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
15+
exit 1
16+
fi
17+
fi
18+
19+
# Install dev dependencies
20+
echo "📦 Installing development dependencies..."
21+
pip install -e ".[dev]"
22+
23+
# Install pre-commit hooks
24+
echo "🪝 Installing pre-commit hooks..."
25+
pre-commit install
26+
27+
# Run against all files for the first time (optional)
28+
echo "🧹 Running formatters on all files..."
29+
pre-commit run --all-files || true
30+
31+
echo "✅ Setup complete!"
32+
echo ""
33+
echo "Now ruff will automatically:"
34+
echo " - Format your code on every commit"
35+
echo " - Fix common linting issues"
36+
echo " - Ensure consistent code style"
37+
echo ""
38+
echo "To manually run formatters: pre-commit run --all-files"

setup-pre-commit.sh

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/bin/bash
2+
# Setup script for pre-commit hooks
3+
4+
echo "Setting up pre-commit hooks for divine-thegraph-token-api..."
5+
6+
# Install dev dependencies (including pre-commit)
7+
echo "Installing dev dependencies..."
8+
pip install -e ".[dev]"
9+
10+
# Install pre-commit hooks
11+
echo "Installing pre-commit hooks..."
12+
pre-commit install
13+
14+
# Run pre-commit on all files to show what it will do
15+
echo "Running pre-commit on all files (this will show and fix any formatting issues)..."
16+
pre-commit run --all-files
17+
18+
echo ""
19+
echo "✅ Pre-commit hooks are now installed!"
20+
echo ""
21+
echo "From now on, every time you commit:"
22+
echo " - Ruff will automatically fix code style issues"
23+
echo " - Ruff formatter will format your code"
24+
echo " - MyPy will check types"
25+
echo " - Various file checks will run"
26+
echo ""
27+
echo "To manually run pre-commit: pre-commit run --all-files"
28+
echo "To bypass pre-commit (not recommended): git commit --no-verify"

0 commit comments

Comments
 (0)