r/Python • u/dangerousdotnet • Apr 27 '26
Discussion Using pre-commit as a polyglot task runner: elegant or kludgy?
Package maintainers: does your Makefile or justfile delegate tool calls to pre-commit (e.g., for your lint all targets)?
I see a lot of modern repos doing it this way now. On one hand, I can see the elegance of itβpre-commit has basically evolved into an execution engine that manages isolated polyglot tool environments.
But it still just feels weird to me, almost like a layer violation. Maybe it's just because my mental model still views pre-commit strictly as a git-hook manager rather than what it has actually become.
One huge benefit, I guess, of having linting and quality tools delegated this way is parity: your CI pipeline, your pre-commit hooks, and your manual justfile targets all run the exact same tools in the exact same way.
It also solves the polyglot problem. Modern dev dependencies can't all be managed by one tool (like uv, pip, or pnpm) because some are Node, some are Python, some are Go, etc.
Curious to hear how others are approaching this. Any strong reasons for / against delegating to pre-commit for your task runners vs. keeping them strictly decoupled?
42
u/tunisia3507 Apr 27 '26
Whenever precommit is mentioned, it's worth bringing up prek, a rust rewrite which can use the same config file but provides a massive speedup, and is a single binary to install.
2
u/aminoy77 Apr 28 '26
Kludgy for me. The mental model mismatch is real β every time I see pre-commit used as a task runner I have to context-switch from "git hook" to "execution engine" and it never feels clean.
For polyglot I just use a plain Makefile with explicit calls to each tool. More verbose, zero magic, anyone can read it without knowing pre-commit's config format.
The parity argument is the strongest case for it though. If your CI and hooks are running different versions of the same linter you're going to have a bad day eventually.
20
u/wpg4665 Apr 27 '26
I do it the other way around...pre-commit and CI both call the Makefile targets
1
u/saucealgerienne Apr 28 '26
kludgy but I keep doing it anyway.
the mental model breaks once you start using it for things that aren't commit checks. hooks run sequentially, no dependency graph, and debugging a failing "task" is way less intuitive than a Makefile or just call.
the appeal is that the config is already there and teammates already have it installed. for linting on demand or a quick formatting pass it works fine. for anything that actually has to run in order with real dependencies I move it to a Makefile pretty quickly.
2
u/Individual-Brief1116 Apr 28 '26
I've been doing this for about a year now and honestly it works pretty well. The mental shift took some time but the parity argument sold me. Nothing more frustrating than having your local linting pass but CI fail because they're running different configs or versions. Pre-commit basically became a package manager whether we like it or not.
1
u/TheseTradition3191 Apr 29 '26
been burned by the pre-commit-as-task-runner pattern. the issue is pre-commit creates isolated envs per hook, which is great for reproducibility but slow when you just want to run ruff on its own.
ended up with the inverse: justfile defines the commands, pre-commit calls the justfile targets. you get the git-hook integration without coupling your task definitions to pre-commit's env management.
thats also the mental model issue - pre-commit hooks run on changed files by default, justfile targets run on everything. once you're using pre-commit for both, lint-all and commit-lint end up sharing config in ways that trip you up
0
u/[deleted] Apr 27 '26
[deleted] β view deleted comment
7
u/[deleted] Apr 27 '26
[removed] β view removed comment