microsoft / vscode-black-formatter

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

Finds no python files to format #458

Closed traits closed 4 months ago

traits commented 4 months ago

System Win10, Python version see below, black ==24.1.1 is installed (error happens with all versions - bundled or not):

2024-02-10 22:41:22.112 [info] v:\bin\scripting\python\current\python-3.10.5.amd64\python.exe -m black --stdin-filename v:\my\invoice\src\main.py -
2024-02-10 22:41:22.112 [info] CWD formatter: v:\my\invoice
2024-02-10 22:41:22.117 [info] No Python files are present to be formatted. Nothing to do 😴

But there is a file and it is known: main.py. So, what?

More verbose output (What is the meaning of the server error?):

2024-02-11 11:12:43.775 [info] [Trace - 11:12:43 AM] Sending notification 'textDocument/didChange'.
2024-02-11 11:12:46.234 [info] [Trace - 11:12:46 AM] Sending request 'textDocument/formatting - (1)'.
2024-02-11 11:12:46.241 [info] [Trace - 11:12:46 AM] Received notification 'window/logMessage'.
2024-02-11 11:12:46.241 [info] v:\bin\scripting\python\current\python-3.10.5.amd64\python.exe -m black --verbose --stdin-filename v:\my\invoice\src\main.py -
2024-02-11 11:12:46.241 [info] [Trace - 11:12:46 AM] Received notification 'window/logMessage'.
2024-02-11 11:12:46.241 [info] CWD formatter: v:\my\invoice
2024-02-11 11:12:46.246 [info] [Trace - 11:12:46 AM] Received notification 'window/logMessage'.
2024-02-11 11:12:46.246 [info] Identified `G:\programming\my\invoice` as project root containing a .git directory.
v:\my\invoice\src\main.py ignored: is a symbolic link that points outside G:\programming\my\invoice
No Python files are present to be formatted. Nothing to do 😴

2024-02-11 11:12:46.246 [info] [Trace - 11:12:46 AM] Received response 'textDocument/formatting - (1)' in 12ms.

Perhaps related:

2024-02-10 22:48:23.452 [info] CWD formatter: v:\my\invoice
2024-02-10 22:48:23.553 [info] Version info for formatter running for G:\programming\my\invoice:

"v" is a mapped device v -> G:\programming. But this has to be supported.

This all works with the now deprecated addon from (https://marketplace.visualstudio.com/items?itemName=joslarson.black-vscode)

Edit: I fixed the incorrect setting of blacks "--verbose" flag by myself and the verbose output becomes more clear now (see large output block above). So, this seems to be some problem with black itself? Or is it the version info gathering run as seen in the last cited output that causes the complete break of the actual formatting task?

karahanyilmazer commented 4 months ago

I faced the same issue. For some reason Black didn't work in git folders. But when I create a new folder with a Python file and make some changes, Black could find the file and format it correctly. Then when I run git init Black stopped working for some reason. Deleting the .git hidden folder seems to resolve the issue after some time.

Solution: I reverted back to v2023.6.0 until the issue is fixed.

karthiknadig commented 4 months ago

This is an issue with black itself (see https://github.com/psf/black/issues/4205). The current option is to pin the extension to older version until a fix is released by black.