From pre-commit to Prek: The Evolution of Code Quality Automation
From manual code reviews to automated pre-commit checks, development practices have evolved rapidly in recent years. Ivan Vyalov, Lead Python Developer at Red Collar, looks at how Ruff and Prek are setting a new standard for speed and reliability in Python development.
The Problem Every Developer Knows
Picture a typical code review. Half the comments are about formatting: “remove trailing whitespace”, “imports aren’t sorted”, “line too long”. Instead of discussing architecture and logic, the team debates style. Sound familiar?
It gets worse when CI fails after a successful review because of a linter. Or someone accidentally commits a file with an API key. Or a forgotten debug print() makes it to production.
Enter pre-commit: Automating the Mundane
Pre-commit is a framework for managing git hooks. Simple idea: check code automatically before every commit. No more style debates, no forgotten debug prints, no accidental secrets in the repository.
How It Works
You install pre-commit:
pip install pre-commit
pre-commit installCreate a .pre-commit-config.yaml configuration:
repos:
- repo: https://github.com/psf/black
rev: 24.8.0
hooks:
- id: black
- repo: https://github.com/PyCQA/isort
rev: 5.13.2
hooks:
- id: isort
- repo: https://github.com/PyCQA/flake8
rev: 7.1.1
hooks:
- id: flake8That’s it. Now on every git commit:
- Black formats the code
- isort sorts imports
- Flake8 checks for errors
If something’s wrong — the commit fails. Code is always clean and consistent.
Success and a New Problem
Pre-commit became an industry standard. Large projects use 20+ hooks:
- Formatters (Black, isort)
- Linters (Flake8, Pylint, MyPy)
- Security (Bandit, detect-secrets)
- Validators (check-yaml, check-json)
But a problem emerged: speed.
On large projects, pre-commit can take 30–60 seconds. Developers start using git commit — no-verify to bypass checks. All that automation becomes pointless.
The First Breakthrough: Ruff
In 2022, Astral released Ruff — a Python linter written in Rust. One tool replaces Black, isort, Flake8, and a dozen other linters. And it’s 10–100x faster.
Before Ruff (3 tools, 3 Python invocations):
- id: black # 10 seconds
- id: isort # 8 seconds
- id: flake8 # 12 seconds
# Total: 30 secondsWith Ruff (1 Rust tool):
- id: ruff # linter - 2 seconds
- id: ruff-format # formatter - 1 second
# Total: 3 seconds10x speedup just by replacing Python tools with Rust equivalents!
The Next Step: Prek
If Ruff sped up Python code checks, what about pre-commit itself? It’s still written in Python, creates virtual environments for each hook, runs them sequentially.
Prek is a complete reimplementation of pre-commit in Rust. Same idea, same configurations, but:
- Parallel hook execution
- Single environment instead of dozens of venvs
- Smart result caching
- Native speed without Python GIL
Migration in 10 Seconds
# On Windows:
powershell -ExecutionPolicy ByPass -c "irm https://github.com/j178/prek/releases/download/v0.2.3/prek-installer.ps1 | iex"# On Linux and macOS:
curl --proto '=https' --tlsv1.2 -LsSf https://github.com/j178/prek/releases/download/v0.2.3/prek-installer.sh | shprek install
prek install-hooks
# Done, ready to work
git commit -m "Now it's fast!"Prek automatically converts .pre-commit-config.yaml and maintains backward compatibility.
How to Start
Option 1: Add Ruff to existing pre-commit
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.8.0
hooks:
- id: ruff
- id: ruff-formatOption 2: Use both
Ruff for Python checks + Prek for speeding up the entire system = maximum performance.
Conclusion
Code quality automation has come a long way. From manual reviews to pre-commit, from Python to Rust. Each step made development a bit faster and more pleasant.
Today, there’s no reason to tolerate slow checks. The tools exist, they’re free and simple to use.
Try Ruff today — it takes 5 minutes and speeds up checks dramatically. And if you’re ready for more — Prek is waiting.
Fast code starts with fast tools.
🛸 Get an estimate of your digital idea 👉 hello@redcollar.co
