Ruff code formatter and pre-commit hooks
python poetry - Running git commit is not properly running pre-commit hooks - Stack Overflow
Switch pre-commit hooks to ruff (100x faster pre-commit, updated code style)
5 Pre-Commit Hooks Every Data Engineer Should Know
Videos
I'm mainly just a hobby programmer but I'm trying to up my CI/CD game. I'm comfortable with mypy and pytest and I'm now looking to integrate ruff. Obviously I know how to launch it, but I'm confused about how its used in practice.
For example, running as:
ruff check ruff format --check
And then manually addressing objections? Or, do you just let ruff make its changes:
ruff check --fix ruff format
...or something else entirely? Thanks.
Hey All,
Just wanted to share my latest blog about my favorite pre-commit hooks that help with writing quality code.
What are your favorite hooks??
TL;DR: Auto-sync your pre-commit hook versions with uv.lock
# Add this to .pre-commit-config.yaml
- repo: https://github.com/tsvikas/sync-with-uv
rev: v0.3.0
hooks:
- id: sync-with-uvBenefits:
-
Consistent tool versions everywhere (local/pre-commit/CI)
-
Zero maintenance
-
Keeps pre-commit's isolation and caching benefits
-
Works with pre-commit.ci
The Problem
PEP 735 recommends putting dev tools in pyproject.toml under [dependency-groups]. But if you also use these tools as pre-commit hooks, you get version drift:
-
uv updatebumpsblackto25.1.0in your lockfile -
Pre-commit still runs
black==24.2.0 -
Result: inconsistent results between local tool and pre-commit.
What My Project Does
This tool reads your uv.lock and automatically updates .pre-commit-config.yaml to match.
Works as a pre-commit (see above) or as a one-time run: uvx sync-with-uv
Target Audience
developers using uv and pre-commit
Comparison
❌ Using manual updates?
-
Cumbersome
-
Easy to forget
❌ Using local hooks?
- repo: local
hooks:
- id: black
entry: uv run black-
Breaks pre-commit.ci
-
Loses pre-commit's environment isolation and tool caching
❌ Removing the tools from pyproject.toml?
-
Annoying to repeatedly type
pre-commit run black -
Can't pass different CLI flags (
ruff --select E501 --fix) -
Some IDE integration breaks (when it requires the tool in your environment)
-
Some CI integrations break (like the black action auto-detect of the installed version)
Similar tools:
-
sync_with_poetry- Poetry version -
sync-pre-commit-lock- PDM/Poetry plugin
Try it out: https://github.com/tsvikas/sync-with-uv
⭐ Star if it helps! Issues and PRs welcome. ⭐