-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
when using --stdin-filename , cannot override auto-found project root with --config #4232
Comments
So, for those looking for a workaround for vscode (where I encountered this), I found that by adding an additional file to be formatted, I can control the project directory it sets, since it will use the "common base directory of all files". I then also add this to the --force-exclude. It's very hacky, but it works. Of course, this means you have to do this from within vscode's settings, not a {
"editor.formatOnSave": true,
"editor.formatOnSaveMode": "file",
"python.formatting.provider": "black",
"black-formatter.args": [
"${workspaceFolder}/.gitignore",
"--force-exclude",
"\\.gitignore\n|submodule"
]
} |
Doesn't work for me :( |
Describe the bug
When using
stdin
+--stdin-filename
, black will always set it's project root to the directory it auto-finds. The docs imply that you can override this by using--config
:However, in practice, specifying
--config
seems to make no difference, and it always uses the auto-found directory.This is problematic when working with .git submodules, as there does not seem to be an easy way to enable formatting for the top-level repository (which you control), and disable it for the subrepos / submodules (which you do NOT control), without making edits in the repos you do not control.
To Reproduce
Our test directory structure will look like:
To create this, and run black, execute this .sh script:
This will give this output:
Expected behavior
Given the docs quoted above, I would expect the
--config
flag to set the project root, and allow excluding of thesubmodule
directory.If the current behavior is intended, then at minimum I think the docs should be clarified... and ideally there should be a way to either explicitly set the project root. (Ideally, within a
pyproject.toml
, you could set an option to always mark it's parent folder as the project root, so the exclude paths it contains would always be relative to "itself").Environment
The text was updated successfully, but these errors were encountered: