Can Black be configured to ignore imports?

6.4k Views Asked by At

I am switching over to using Black for all my Python projects from now on. Till now I had been using autopep8 as my auto-formatter and isort to sort my imports. But while using Black I found out that Black alone does the job of isort too alongside formatting my code. While I do not mind the way Black sorts my imports, I would still like to use isort to handle my imports and I would like Black to handle only my code, not the imports. So, is there any way to configure Black to only format my code and not touch the imports? I am using VS Code by the way so some help on how to apply the configuration in VS Code will help too. Thanks!

1

There are 1 best solutions below

1
On BEST ANSWER

Add those to jobs setting in vscode, it should do the trick

{
    "python.formatting.provider": "black",
    "[python]": {
        "editor.codeActionsOnSave": {
            "source.organizeImports": true
        }
    }
}