-
Notifications
You must be signed in to change notification settings - Fork 36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Black formatter does not format symlinked files (Black 24.1.1) #444
Comments
What is the version of black that you have in your terminal? can you update it to match the latest from the extension. also the equivalent way of launching it is this:
|
Thank you very much. The version of black, I had in terminal is |
The problem is back again after I restarted VS Code the next day. In terminal, now I also have |
I am also having this issue. No formatter is working in vscode for python files specifically. |
I am also facing this issue. I have been using this extension for a while without ever installing the black python package in the virtual environment. Installing the latest version of this package did not resolve the issue. Of course, running |
I downgraded the black formatter extension to the previous version (v2023.6.0) and it solved the issue. |
Just to verify in you run the following command do you see the formatted output?
|
comes from black itself. This is looking like a bug in the latest version of |
Yes, it works and I get the formatted output |
Unfortunately I am not able to repro this locally: formatting_with_black_latest.mp4Can you provide more detail on the environment you are using like version of python, packages installed etc. |
None of the formatters are working. Not sure what else to try. Unable.to.Format.Python.mov |
After update to 1.86.0, this extension stopped working with non-bundled black version. Log with errors
The log above is for black Log with success
And we can't easily switch project to the latest black version, unfortunately. My system detailsMy vscode:
OS:
|
OS: VS Code:
VS Code extensions installed on remote server
In user settings.json
Conda environment and packages
Another thing, I noticed just now is I have the issue of black formatter not working when /path/to/my_code.py follows a symlink. Black formatter is working if I open my code in VS Code without following a symlink. |
Same issue here, no formatting anymore on VSC 1.86.0 with Black...
So without using the mapped drive created with subst, I can still continue to work. |
@werwack The symlink issue is with black itself, it was fixed in version 24.0.0. @side2k If you have dependency on specific version of black then I recommend doing this:
The above settings will make the extension use the bundled libs for communication, but black from your environment. |
@karthiknadig any suggestions for me ? I've tried all of the above but still am not able to get it to work. |
@stefmf Can you open your Output > Black Formatter logs and see what it says? |
never mind i see the issue. it works but stops, if there is syntax issues. |
I have black, 24.1.1 in terminal which works fine. Is the black shipped with the VS Code extension > =black, 24.0.0? If yes, why is it still not working in a path with symlink? |
@de-ranit It might have to do with how
The only think I can think of is that there is some mismatch due to which directory is used for
|
Can confirm that |
I also tried |
Leaving this issue open to update bundled |
Black released 24.2.0, hopefully that fixes issues here |
In case this ever comes back in the future, I wrote the following script for debugging this before realizing that it had already been reported and fixed (note that a previous version of black had problems with symlinks only in the presence of pyproject.toml): #!/usr/bin/env bash
verbose=""
if [ "$1" == "-v" ] || [ "$1" == "--verbose" ]; then
verbose=1
set -x
fi
if [ -z "$PYTHON" ]; then
PYTHON=python
fi
"$PYTHON" -m black --version
uname -a
testdir="$(mktemp -d)"
trap "rm -rf $testdir" EXIT
cd "$testdir"
subdir="."
mkdir -p "directory/$subdir"
ln -s directory symlink
cd "directory/$subdir"
runtest() {
for cwd in "directory" "symlink"; do
for usedir in "directory" "symlink"; do
cd "$testdir/$cwd/$subdir"
usefile="$testdir/$usedir/$subdir/test.py"
echo "import numpy as np# foo" > test.py
printf "%s in %s using %s..." "$1" "$cwd" "$usedir"
if [ -n "$verbose" ]; then
printf "\n"
echo "import numpy as np# foo" | "$PYTHON" -m black --stdin-filename "$usefile" -
printf "=====================================\n"
else
result="$(echo "import numpy as np# foo" | "$PYTHON" -m black --stdin-filename "$usefile" - 2>&1)"
if printf -- "$result" | grep -q "1 file reformatted."; then
printf "pass\n"
else
printf "fail\n"
fi
fi
done
done
}
runtest "without pyproject.toml"
touch pyproject.toml
runtest "with pyproject.toml" |
@JasonGross you should recommend this as a smoke test to |
Today, my VS Code got updated to the following version:
Version: 1.86.0 (Universal)
Commit: 05047486b6df5eb8d44b2ecd70ea3bdf775fd937
Date: 2024-01-31T10:29:15.765Z
Electron: 27.2.3
ElectronBuildId: 26495564
Chromium: 118.0.5993.159
Node.js: 18.17.1
V8: 11.8.172.18-electron.0
OS: Darwin arm64 23.2.0
I have Black Foramatter v2024.0.0.
I am not able to format my Python code after the VS Code update. The output log is following:
But running
black my_code.py
works perfectly fine. It doesn't work only when I right click on my code and select format document with -> black formatter. Black formatter used to work perfectly before the VS Code update.The text was updated successfully, but these errors were encountered: