microsoft / vscode-black-formatter

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

Black Formatter Not Working on Python Files in Git-Initialized Folders in VS Code #454

Closed karahanyilmazer closed 7 months ago

karahanyilmazer commented 7 months ago

Description

I've encountered an issue where the Black formatter does not format Python files in git folders. The formatter works as expected on Python files in non-Git folders, but once a folder is initialized as a Git repository, newly created Python files within that folder are not formatted. Deleting the .git folder restores Black's functionality.

Steps to Reproduce

  1. Create a new folder and place a Python file inside. Confirm that Black formats this file correctly in VS Code.
  2. Initialize the folder as a Git repository using git init.
  3. Create another Python file in the Git-initialized folder. Observe that Black does not format this new file.
  4. Delete the .git folder from the project directory.
  5. Create another Python file and observe that Black now formats it correctly.

Expected Behavior

Black should format Python files regardless of the presence of a Git repository in the project folder.

Actual Behavior

Black does not format Python files in folders that have been initialized as Git repositories.

Error Messages

2024-02-08 15:41:41.341 [info] [Trace - 3:41:41 PM] Sending request 'textDocument/formatting - (8)'. 2024-02-08 15:41:41.344 [info] [Trace - 3:41:41 PM] Received notification 'window/logMessage'. 2024-02-08 15:41:41.344 [info] c:\Users\yilma\AppData\Local\Programs\Python\Python311\python.exe -m black --skip-string-normalization --stdin-filename c:\Files\Coding\Python\Neuro\testing\testing_new.py - 2024-02-08 15:41:41.345 [info] [Trace - 3:41:41 PM] Received notification 'window/logMessage'. 2024-02-08 15:41:41.345 [info] CWD formatter: c:\Files\Coding\Python\Neuro\testing 2024-02-08 15:41:41.348 [info] [Trace - 3:41:41 PM] Received notification 'window/logMessage'. 2024-02-08 15:41:41.348 [info] No Python files are present to be formatted. Nothing to do 😴

2024-02-08 15:41:41.348 [info] [Trace - 3:41:41 PM] Received response 'textDocument/formatting - (8)' in 8ms.

Troubleshooting Steps Attempted

System Configuration

I would appreciate any insights or suggestions on resolving this issue. If further information or testing is required, I'm happy to provide it.

Edit: Switching to Black v2023.6.0 solved my issue.

karthiknadig commented 7 months ago

This is an issue with black itself see https://github.com/psf/black/issues/4205 Duplicate https://github.com/microsoft/vscode-black-formatter/issues/444