question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Format on save doesn't work for black when using conda run

See original GitHub issue

Environment 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:

  1. Install Black for Python pip install black:
  2. Edit the following settings in settings.json:
"python.formatting.blackArgs": [
        "--line-length",
        "100"
    ],
"editor.formatOnSave": true,
"python.formatting.provider": "black",
  1. Create a file with the following content:
dict(
    foo="bar",
    foo4="bar",foo5="bar"
)
  1. 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:closed
  • Created 4 years ago
  • Comments:5

github_iconTop GitHub Comments

2reactions
karrtikrcommented, Jan 10, 2020

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.

0reactions
karrtikrcommented, Dec 14, 2022
Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found