Description
Is your feature request related to a problem? Please describe.
This is the current behaviour for handling .gitignore
:
If --exclude is not set, Black will automatically ignore files and directories in .gitignore file(s), if present.
If you want Black to continue using .gitignore while also configuring the exclusion rules, please use --extend-exclude.
However, my case does not fill in those two scenarios.
-
Our project is a build system, and one of its subpackages is named
build
. -
The directory named
build
is listed inDEFAULT_EXCLUDES
:
Line 2 in a4032dc
- Black does not have an option to remove items from the default list, so my only alternative to workaround this is redefining the
exclude
option/setting. By doing so, black stops honouring my.gitignore
file 😭
Alternatives I've tried
-
exclude
has precedence overinclude
, so doing--include '/build/|\.pyi?$'
does not work. -
The only way I could make it work was additionally informing the full path for the Python files inside the
build
directories:black . foo/cli/build/*.py tests/foo/cli/build/*.py
. But this is not an ideal solution since I cannot specify this as black configuration inpyproject.toml
. As a result, developers runningblack .
will think they're formatting everything (no warning about the skipped files), and those paths will have to be hardcoded somewhere else (Makefile, tox.ini, ...).
Describe the solution you'd like
I want black .
to format all the Python files in the repository, skipping all the paths listed in .gitignore
.
I have the same problem with ruff and isort, since they also exclude build
by default. But both have specific options to control the reading of the .gitignore
file:
- respect-gitignore in ruff
- skip-gitignore in isort
Then I can use settings to workaround this issue:
[tool.ruff]
# Files in `foo/cli/build/` are ignored by ruff because the `exclude`
# list contains the `build` word by default. We redefine it with just
# `.git`, since the other paths are already listed in `.gitignore`.
respect-gitignore = true
exclude = [".git"]
Activity