Closed rjwalters closed 1 month ago
@rjwalters In the logs Output > Black Formatter, it should have the exact version that is loaded by the extension.
@rjwalters When you run black
from the command line, it might run black
from different location than the one that the extension runs. This really depends on which python you have selected. because python -m black
can be different depending on which python
in running. The useBundled
case will always run the bundled version and the version info there should be available in readme or in the extension welcome page from the extension view.
You can also force the extension to use the black
binary that you have installed globally, by setting "black-formatter.path": ["black"]
Okay here is what I see for each import strategy:
2024-05-03 10:00:15.229 [info] Global settings received on server:
{
"cwd": "/",
"workspace": "/",
"args": [],
"path": [],
"interpreter": [],
"importStrategy": "fromEnvironment",
"showNotifications": "off"
}
2024-05-03 10:00:15.229 [info] sys.path used to run Server:
/Users/rwalters/.vscode/extensions/ms-python.black-formatter-2024.2.0/bundled/tool
/opt/homebrew/Cellar/python@3.12/3.12.3/Frameworks/Python.framework/Versions/3.12/lib/python312.zip
/opt/homebrew/Cellar/python@3.12/3.12.3/Frameworks/Python.framework/Versions/3.12/lib/python3.12
/opt/homebrew/Cellar/python@3.12/3.12.3/Frameworks/Python.framework/Versions/3.12/lib/python3.12/lib-dynload
/Users/rwalters/.vscode/extensions/ms-python.black-formatter-2024.2.0/bundled/libs
2024-05-03 10:00:15.231 [info] /Users/rwalters/Documents/GitHub.nosync/python-robb/myenv/bin/python -m black --version
2024-05-03 10:00:15.231 [info] CWD formatter: /Users/rwalters/Documents/GitHub.nosync/python-robb
2024-05-03 10:00:15.275 [info] Version info for formatter running for /Users/rwalters/Documents/GitHub.nosync/python-robb:
black, 24.3.0 (compiled: no)
Python (CPython) 3.12.3
vs
2024-05-03 10:00:15.275 [info] SUPPORTED black>=22.3.0
FOUND black==24.3.0
2024-05-03 09:57:38.208 [info] Global settings received on server:
{
"cwd": "/",
"workspace": "/",
"args": [],
"path": [],
"interpreter": [],
"importStrategy": "useBundled",
"showNotifications": "off"
}
2024-05-03 09:57:38.208 [info] sys.path used to run Server:
/Users/rwalters/.vscode/extensions/ms-python.black-formatter-2024.2.0/bundled/libs
/Users/rwalters/.vscode/extensions/ms-python.black-formatter-2024.2.0/bundled/tool
/opt/homebrew/Cellar/python@3.12/3.12.3/Frameworks/Python.framework/Versions/3.12/lib/python312.zip
/opt/homebrew/Cellar/python@3.12/3.12.3/Frameworks/Python.framework/Versions/3.12/lib/python3.12
/opt/homebrew/Cellar/python@3.12/3.12.3/Frameworks/Python.framework/Versions/3.12/lib/python3.12/lib-dynload
2024-05-03 09:57:38.210 [info] /Users/rwalters/Documents/GitHub.nosync/python-robb/myenv/bin/python -m black --version
2024-05-03 09:57:38.210 [info] CWD formatter: /Users/rwalters/Documents/GitHub.nosync/python-robb
2024-05-03 09:57:38.256 [info] Version info for formatter running for /Users/rwalters/Documents/GitHub.nosync/python-robb:
black, 24.3.0 (compiled: no)
Python (CPython) 3.12.3
2024-05-03 09:57:38.256 [info] SUPPORTED black>=22.3.0
FOUND black==24.3.0
It doesn't seem like importStrategy gets me to the same black version that gets used in the terminal...
I suppose this problem will go away when the extension updates the bundled black to 23.4.2+
@rjwalters This means that the python
that is being used by extension is not the same python where you installed the terminal black
.
With fromEnvironment
the black
being used is /Users/rwalters/Documents/GitHub.nosync/python-robb/myenv/bin/python -m black
Try updating that version.
> /Users/rwalters/Documents/GitHub.nosync/python-robb/myenv/bin/python -m pip -U black
Then reload.
I ran into the same problem reported in #419 this morning related to parsing nested double quotes in formatted strings like
f"{"value"}"
.It was especially confusing because I was able to format the file without any issue using commands in the vscode terminal:
This sent me down a rabbit hole of trying to figure out how vscode was misconfigured.
I tried changing
black-formatter.importStrategy
to eitherfromEnvironment
oruseBundled
but both settings resulted in the same error message...How can I check which version of black the extension uses?