-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
black does not exclude files in git submodules #3040
Comments
We've also been seeing issues where black doesn't correctly handle
It would be nice for black to match git behaviour 1:1 by default, without needing CLI workarounds. |
I've been trying to write a test for this and I'm concerned that the existing exclude tests do not reflect real-world usage. The existing tests make use of the Line 1836 in 6c1bd08
get_sources() : Line 595 in 6c1bd08
However, the result of Lines 458 to 459 in 6c1bd08
However, in all of the include/exclude tests the root folder is manually set. None of the tests will reproduce the behaviour that occurs if |
In my branch, I have added a test which reproduces the behaviour of this bug: https://github.com/janjachnik-dyson/black/tree/feature/manually_specify_project_root The problem only seems to occur when the full file path is given, I added tests for both scenarios (base path and full path). To make sure the tests are run correctly, I now set So now we have the bug reproduced in a test, I'd like some feedback/guidance on how to fix it. I've suggested one solution in a draft PR here: #3116, which essentially gives the ability to manually override the project root. Is my solution a viable option, or should the bug be fixed in a way that doesn't require manual intervention? |
I was expecting that black would never try to format files in any submodule, but maybe our team has a different setup than other python project. We have googletest as a submodule (i think is the normal way to use gtest), which seems to have python2 scripts which makes black fail. I could file a different feature-request for "black option to exclude files in git submodules"? (Or would that be a dupe of this issue?) |
Any news on this front? This is a major nuisance for us, would be great if a workaround was available. |
@derpda No update currently. I'm open to specifying the project root. I'll try to take a look at the linked PR soon-ish. A admittedly hacky workaround is to create an empty file at the root of your project and pass that file along with the file from the submodule. black empty.py submodule/yourcode.py This way Black will be forced to use the common parent of the two files as the project root. |
Thank you for getting back to me on this! That is probably beyond the scope of this issue, but if you (or someone else) knows something, that would be much appreciated! |
Still relevant. |
Describe the bug
black does not exclude files in git submodules when full filename is passed
To Reproduce
I created an example project with a git submodule to test. The super-project has a pyproject.toml which excludes the subproject:
Commands to clone and reproduce bug:
The output:
Expected behavior
subproject/file.py
would be ignored because its path matches the force-exclude regex in pyproject.tomlEnvironment
Additional context
We use black from within Visual Studio Code, where it is always called with the full filename. If black is manually run on the root folder of the super-project, the excludes are handled correctly. Within VSCode we pass the
--config
argument to specify the correct configuration file of the super-project.Possible solution
The problem occurs because black decides the project root by recursively searching parent directories for
.git
,.hg
andpyproject.toml
files. In this case, the project root becomes the subproject folder (due to .git) and the exclude regex is compared against the path relative to the project root, which no longer contains thesubproject
string.As a possible fix, I added the option to manually specify the project root:
janjachnik-dyson@6fc3368
Then, the following command works to properly exclude the file:
If this sounds like a valid fix/workaround, I'll raise a PR. Or is there a better way to handle excludes with git submodules?
The text was updated successfully, but these errors were encountered: