Open pmolodo opened 8 months ago
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 pyproject.toml
. In your .vscode/settings.json
, it looks like this:
{
"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