Skip to content
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 Not Working on Python Files in Git-Initialized Folders in VS Code #454

Closed
karahanyilmazer opened this issue Feb 8, 2024 · 1 comment
Labels
triage-needed Issue is not triaged.

Comments

@karahanyilmazer
Copy link

karahanyilmazer commented Feb 8, 2024

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

  • Upon initializing a Git repository and attempting to format a Python file, there are no explicit error messages from Black indicating a failure to format. The functionality silently fails. The problem is that no Python files are found.

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

  • Checked workspace and user settings in VS Code to ensure there were no conflicts or misconfigurations specifically affecting files in Git repositories.
  • Confirmed that the issue persists across different projects and is reproducible following the steps above.
  • Tested Black's functionality in folders both before and after initializing them as Git repositories to confirm the behavior is consistent with the presence of the .git directory.
  • Reviewed VS Code and Black formatter logs for any warnings or errors that might indicate the cause of the issue, but found nothing directly relevant.

System Configuration

  • VS Code Version: 1.86.1
  • Black Version: v2024.0.0
  • Operating System: Windows 11
  • Python Version: 3.11.3
  • Git Version: 2.40.0.windows.1

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.

@github-actions github-actions bot added the triage-needed Issue is not triaged. label Feb 8, 2024
@karthiknadig
Copy link
Member

karthiknadig commented Feb 8, 2024

This is an issue with black itself see psf/black#4205
Duplicate #444

@karthiknadig karthiknadig closed this as not planned Won't fix, can't repro, duplicate, stale Feb 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
triage-needed Issue is not triaged.
Projects
None yet
Development

No branches or pull requests

2 participants