2

As stated on this answer, one can check (and set) on settings.json the formatters used by VS Code.

For Python, I use black:

settings.json

...
"python.formatting.provider": "black"
...

I think I found an issue involving black, but I'm only able to reproduce it in VS Code, not when running it from the terminal.

I'd like to know which version (or even better, the location) of the black binary is being used by VS Code. Ideally, I would also like to change it, in order to check on which versions I can (or cannot) reproduce the issue.

What I know for sure is that VS Code is not using the black binary on my path; autoformatting keeps working even if I remove it from the path. ( e.g.: mv /home/sam/.local/bin/black /home/sam/.local/bin/black.bak)

Sam
  • 1,222
  • 1
  • 14
  • 45

2 Answers2

2

Open OUTPUT panel, choose Python channel in the drop-down list, then format the document, you will get it.

If you want to use a custom version of black, you can specify the Black Path: Specified

alexzshl
  • 902
  • 6
  • 6
  • The comand I see there is `~/.vscode/extensions/ms-python.python-2020.5.86806/pythonFiles/pyvsc-run-isolated.py`, which receives `black` as a string parameter. Still I can't figure where the `black` binary for the extension is located. – Sam Jun 12 '20 at 22:42
  • 1
    It means the extension ms-python has some built-in formatting providers, include black. If you want to use your own black.exe, you have to specified the black path. – alexzshl Jun 13 '20 at 02:47
0

After you select the right environment, take the command 'pip show black'. It will tell you the location of black which you are using. Or you can just take the command 'pip install black', if the black has been installed, it will show you: "Requirement already satisfied: black in {the location of black} {version}". In fact, if you are using the virtual environment, it just locates in the xxx.venv\lib\site-packages.

In a python environment, you can only have one version of one package at one time. You can take these commands: 1. 'pip show black' to get the specific information of the black package. 2. "pip install 'black=={version}'" to install the specific version of black. 3. 'pip install --upgrade black' to install the last version of black.

Steven-MSFT
  • 7,438
  • 1
  • 5
  • 13