Format on save doesn't work for black when using conda run
See original GitHub issueEnvironment data
- VS Code version: 1.41.1
- Extension version (available under the Extensions sidebar): 2020.1.57204
- OS and version: Windows 10 / CentOS 7.5 (tried on both)
- Python version (& distribution if applicable, e.g. Anaconda): 3.7.3.final.0 (Anaconda3)
- Type of virtual environment used (N/A | venv | virtualenv | conda | …): N/A
- Relevant/affected Python packages and their versions: N/A
- Jedi or Language Server? (i.e. what is
"python.jediEnabled"
set to; more info #3977): jediEnabled set to true
Steps to Reproduce:
- Install Black for Python
pip install black
: - Edit the following settings in
settings.json
:
"python.formatting.blackArgs": [
"--line-length",
"100"
],
"editor.formatOnSave": true,
"python.formatting.provider": "black",
- Create a file with the following content:
dict(
foo="bar",
foo4="bar",foo5="bar"
)
- Save the file (name it:
black_bug.py
). The file contents do not change, but the expected results was for the file to be changed to:
dict(foo="bar", foo4="bar", foo5="bar")
(the same as executing black --line-length 100 black_bug.py
)
I do see that the following command has been executed in the console (output > Python)
conda run -n base python -m black --line-length 100 --diff --quiet ~/black_bug.py
cwd: ~
The same problem happens when using autopep8 or other formatter
Issue Analytics
- State:
- Created 4 years ago
- Comments:5
Top Results From Across the Web
Black formatter does not work in VSCode after installing ...
1 Answer 1 · Run pip uninstall black to delete black in current activated conda environment; · In Settings.json, set "python.formatting.provider": ...
Read more >Black - :: Anaconda.org
In return, Black gives you speed, determinism, and freedom from pycodestyle nagging about formatting. You will save time and mental energy for more...
Read more >Advanced Visual Studio Code for Python Developers
Run and monitor Python tests; Lint and format your code automatically; Leverage type annotations and Pylance to write code faster with higher accuracy ......
Read more >VSCode: Using Black to automatically format Python
Black is "the uncompromising Python code formatter." It can be configured to automatically format your code whenever you save a file in VSCode....
Read more >Code formatting in Jupyter cells. TL;DR - Medium
If you are using exclusively Jupyterlab, I now recommend using this ... First, you install the black library using conda from the conda-forge...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I am able to reproduce the issue, thanks. The issue happens only with the conda interpreter, so you can select some other interpreter as a workaround.
It will be fixed along with https://github.com/microsoft/vscode-python/issues/9490.
Closing as fixed according to https://github.com/microsoft/vscode-python/issues/9487#issuecomment-572816972