microsoft / vscode-black-formatter

Formatting support for Python using the Black formatter
https://marketplace.visualstudio.com/items?itemName=ms-python.black-formatter
MIT License
146 stars 35 forks source link

Python version check fails when installed black version supports older python #372

Closed ryancausey closed 8 months ago

ryancausey commented 8 months ago

I ran into an issue in one of my older python 3.7 environments where the installed version of black, 23.3.0, would be able to format files but the extension would refuse to start because of the checkVersion function returned false.

I believe that if the black-formatter.importStrategy is set to fromEnvironment, this version check should not apply under the assumption that the installed black version in the environment works with the python version used for that environment.

karthiknadig commented 8 months ago

@ryancausey That check also ensures that the server can run successfully. We cannot remove that check, however, there is a way to run older black versions. To use a older black version: set black-formatter.interpreter to a compatible version of python, set importStrategy to useBundled, but set black-interpreter.path to black from the environment. this will run the server using the compatible version of python, but use black from your environment.

Another option is to pin the extension to a older version which supported python 3.7.