Pre-commit vs Prek - The Differences

Pre-commit vs Prek - The Differences 图片 1
Pre-commit vs Prek - The Differences 图片 2

If you’ve been working with Python (or really any language) for a while, chances are you’ve used pre-commit. It’s been the de facto standard for managing git hooks for years. You define your hooks in a.pre-commit-config.yaml, run pre-commit install, and you’re good to go. It handles the installation and execution of hooks written in any language, without requiring root access.

But recently, as I found out at FOSDEM, a new tool has been making the rounds: prek. It’s like a version of pre-commit, built in Rust. And if you’ve been following the Python ecosystem, you’ll notice a trend here. First we got Ruff as a replacement for Flake8, Black, and isort. Then uv came along to replace pip venv (and maybe even Poetry). Now prek is here to speed things up as well.

The Rust rewrite of pre-commit is gaining traction fast. For a couple of my projects I decided to give prek a shot and see how it compares to good old pre-commit. Let me walk you through the differences.

A quick recap

pre-commitpre-commit has been around since 2014 and has a massive ecosystem. It’s a multi-language package manager for git hooks. You specify the hooks you want, and pre-commit manages everything: downloading the tools, setting up isolated virtual environments, and running the hooks on every commit.

A typical configuration looks like this:

1 2 3 4 5 6 7 8 9 10 11 12

repos: • repo:github.com/pre-commit/pre-commit-hooks rev: v4.6.0 hooks: • id: check-yaml • id: end-of-file-fixer • id: trailing-whitespace • repo:github.com/astral-sh/ruff-pre-commit rev: v0.8.0 hooks: • id: ruff • id: ruff-format

Getting started is straightforward:

1 2

pip install pre-commit pre-commit install --install-hooks

That’s it. Now every time you commit, your hooks will run.

prekprek is a drop-in replacement for pre-commit, built in Rust by j178. It’s designed to be faster, dependency-free, and fully compatible with your existing.pre-commit-config.yaml. That last part is key: you don’t have to…

添加评论
点赞收藏
点踩分享查看原文
评论
?
参与讨论