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
| \.git
| \.hg
| \.mypy_cache
| \.tox
| \.venv
| _build
| buck-out
| build
| dist
)/
| ^migrations/
'''
I have also configured precommit.
But on running pre-commit run --all-files
Black formats the migration folders also
how can I configure black
Use the --no-verify option to skip git commit hooks, e.g. git commit -m "commit message" --no-verify . When the --no-verify option is used, the pre-commit and commit-msg hooks are bypassed.
The pre-commit hook is run first, before you even type in a commit message. It's used to inspect the snapshot that's about to be committed, to see if you've forgotten something, to make sure tests run, or to examine whatever you need to inspect in the code.
The goal of pre-commit hooks is to improve the quality of commits. This is achieved by making sure your commits meet some (formal) requirements, e.g: that they comply to a certain coding style (with the hook style-files ). that you commit derivatives such as README.md or .
this issue on the black
issue tracker outlines your particular problem
pre-commit
finds all the python files, then applies pre-commit
's exclusion, and then passes that list of files to the underlying tools (in this case black
)
black
currently (at the time of writing) will format all files listed on the command line -- independent of black
's exclude
pattern
the suggestion is to use pre-commit
's exclusion (via your .pre-commit-config.yaml
) such that those files are never passed to black at all:
- id: black
exclude: ^migrations/
note: unlike black, pre-commit will only ever lint files which are checked into your git repository, so the laundry list of exclusion is unnecessary here (.git
/ .mypy_cache
/ etc.)
disclaimer: I'm the author of pre-commit
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With