For questions regarding the pre-commit framework, not to be confused with git pre-commit hooks generally. Use this tag only when your question involves the framework. The tool pre-commit is a framework for managing and maintaining multi-language pre-commit hooks.
Questions tagged [pre-commit.com]
309 questions
63
votes
5 answers
pre-commit fails to install isort 5.11.4 with error "RuntimeError: The Poetry configuration is invalid"
pre-commit suddenly started to fail installing the isort hook in our builds today with the following error
[INFO] Installing environment for https://github.com/pycqa/isort.
[INFO] Once installed this environment will be reused.
[INFO] This may take…

bagerard
- 5,681
- 3
- 24
- 48
51
votes
5 answers
black as pre-commit hook always fails my commits
I'm trying to use pre-commit to manage Black as a Git pre-commit hook, but I must be doing it wrong.
In my pre-commit config file I have:
- repo: https://github.com/psf/black
rev: 19.3b0
hooks:
- id: black
What I'm expecting to…

Jean-François Corbett
- 37,420
- 30
- 139
- 188
49
votes
2 answers
Exclude some files on running black using pre-commit
I want to configure black in pre-commit and exclude precommit from checking any migrations folder.
My pyproject.toml looks like this
[tool.black]
line-length = 79
target-version = ['py37']
include = '\.pyi?$'
exclude = '''
(
/(
\.eggs
|…

Suyash Salampuria
- 765
- 2
- 6
- 9
34
votes
2 answers
Where does pre-commit install "environments"?
I'm trying to setup pre-commit for a Python project's repository. Upon running pre-commit install I see an output like this:
[INFO] Installing environment for https://github.com/asottile/seed-isort-config.
[INFO] Once installed this environment will…

planetp
- 14,248
- 20
- 86
- 160
32
votes
1 answer
How to run custom shell script file before pre commit hook
In my python project, I have pre-commit-config.YAML where I want to create my custom file.
The intention of this file is fail git commit if python lint errors are greater than certain numbers. The following command will be used to count lines
pylint…

Kedar Shinde
- 379
- 1
- 4
- 5
21
votes
5 answers
Ignoring Django Migrations in pyproject.toml file for Black formatter
I just got Black and Pre-Commit set up for my Django repository.
I used the default config for Black from the tutorial I followed and it's been working great, but I am having trouble excluding my migrations files from it.
Here is the default…

Clark Sandholtz
- 701
- 6
- 14
20
votes
2 answers
How to have a single source of truth for poetry and pre-commit package version?
I'm looking into this Python project template. They use poetry to define dev dependencies
[tool.poetry.dev-dependencies]
black = {version = "*", allow-prereleases = true}
flake8 = "*"
isort = "^5.6"
mypy = ">0.900,<1"
...
They use also pre-commit…

floatingpurr
- 7,749
- 9
- 46
- 106
19
votes
2 answers
pylint and pre-commit hook unable to import
My project structure looks like this:
project/
app/
main.py
venv/
.pylintrc
.pre-commit-config.yaml
When I am trying to edit project/app/main.py and it fails with
Unable to import 'psycopg2' (import-error)
But when I am trying to…

palkan
- 321
- 2
- 5
18
votes
1 answer
VSCode integrated source control and pre-commit
When using https://pre-commit.com with VSCode hooks that depend on packages installed in a Python venv. In pre-commit on can specify to use "system" as environment. This works great from the terminal with desired venv active.
However using the…

Martin Gran
- 241
- 1
- 2
- 5
17
votes
2 answers
How to uninstall pre-commit
Following the "non administrative installation" instructions on Pre-Commit's website, I ran the following command:
curl http://pre-commit.com/install-local.py | python
These instructions provide the following note: "(To upgrade: run again, to…

kuanb
- 1,618
- 2
- 20
- 42
16
votes
2 answers
pre-commit fails to install isort 5.10.1 with error "RuntimeError: The Poetry configuration is invalid"
[INFO] Installing environment for https://github.com/pycqa/isort.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
An unexpected error has occurred: CalledProcessError: command:…

LOTEAT
- 181
- 1
- 4
15
votes
2 answers
running pytest as a pre-commit hook // no such file or directory issue
in my Python project I use pytest as a pre-commit hook. Some tests create and delete temporary files, everything works fine when I run pytest . However, when I run git commit and pre-commit hook triggers pytest, some tests fail…

Alexey Abramov
- 435
- 1
- 3
- 16
15
votes
1 answer
With pre-commit, how to use some hooks before commit and others before push
Some hooks can take a while to run, and I would like to run those before I push, but not before each particular commit (for example, pylint can be a bit slow).
I've seen the following:
Question: Using hooks at different stages
mesos-commits mailing…

baxx
- 3,956
- 6
- 37
- 75
14
votes
2 answers
Run pre-commit only on certain branches
I am looking for a configuration in the .pre-commit-config.yaml to exclude pre-commit from being run on certain branches, or to run it only on some branches. I don't know if this feature not implemented, or if I am missing it in the docs.
Thanks!

Alex Martínez Ascensión
- 153
- 4
13
votes
1 answer
Understanding how to configure pre-commit with repo: local
I'm trying to get pre-commit working at work (I have it working on personal computer). Our security setup will not allow pre-commit to reference external repos and pip install external packages from them.
It seems like my options are:
Keep a copy…

Ryan
- 133
- 1
- 1
- 5