Skip to content

Formatting fails to update files due to path quoting issues #14078

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

Closed
CodePidgy opened this issue Sep 24, 2020 · 13 comments
Closed

Formatting fails to update files due to path quoting issues #14078

CodePidgy opened this issue Sep 24, 2020 · 13 comments
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug

Comments

@CodePidgy
Copy link

CodePidgy commented Sep 24, 2020

Black seems to not be working, and initially I thought it was a bug in my code or something, but running python -m black main.py works just fine. What's happening?

Environment data

  • VS Code version: 1.49.1
  • Extension version (available under the Extensions sidebar): v2020.9.111407
  • OS and version: Windows 10
  • Python version (& distribution if applicable, e.g. Anaconda): 3.8.5
  • Type of virtual environment used (N/A | venv | virtualenv | conda | ...): venv
  • Relevant/affected Python packages and their versions: black: 20.8b1
  • Relevant/affected Python-related VS Code extensions and their versions: None
  • Value of the python.languageServer setting: Jedi

Expected behaviour

Code to be formatted after running "Format Document" (Shift+Alt+F).

Actual behaviour

Black runs for a split second and nothing happens.

Steps to reproduce:

  1. Have a line over 80 characters long which should be formatted
  2. Run formatter
  3. Be dissapointed at your still ugly code.

Logs

> f:\Programs\Python\Lynez Experiment\env\Scripts\python.exe "D:/Data/Microsoft Visual Studio Code/extensions/ms-python.python-2020.9.111407/pythonFiles/pyvsc-run-isolated.py" black --diff --quiet "f:\Programs\Python\Lynez Experiment\main.py"
cwd: f:\Programs\Python\Lynez Experiment
> f:\Programs\Python\Lynez Experiment\env\Scripts\python.exe "D:/Data/Microsoft Visual Studio Code/extensions/ms-python.python-2020.9.111407/pythonFiles/pyvsc-run-isolated.py" black --diff --quiet "f:\Programs\Python\Lynez Experiment\main.py"
cwd: f:\Programs\Python\Lynez Experiment

@CodePidgy CodePidgy added triage-needed Needs assignment to the proper sub-team bug Issue identified by VS Code Team member as probable bug labels Sep 24, 2020
@CodePidgy
Copy link
Author

Note: Issue #14054 seems to have the same problem, but nobody seems to have an answer.

@karthiknadig karthiknadig self-assigned this Sep 24, 2020
@ghost ghost removed the triage-needed Needs assignment to the proper sub-team label Sep 24, 2020
@CodePidgy
Copy link
Author

I'd be more than happy to help, if anyone told me how to.

@karthiknadig
Copy link
Member

@DRACL10N #14054 was due to incorrect argument configuration provided by the user. In your case I would manually run the command:

f:\Programs\Python\Lynez Experiment\env\Scripts\python.exe "D:/Data/Microsoft Visual Studio Code/extensions/ms-python.python-2020.9.111407/pythonFiles/pyvsc-run-isolated.py" black --diff --quiet "f:\Programs\Python\Lynez Experiment\main.py"

and see if that returns the diff correctly. If there are any warnings are errors printed or if it takes too long then formatting will not work. If there are no errors or warnings, then please share your settings and if possible the repro code.

@CodePidgy
Copy link
Author

CodePidgy commented Sep 25, 2020

@karthiknadig it gives me the exact same output as if I were to press Shift-Alt-F. It shows me where it would change something, but does nothing about it.

@CodePidgy
Copy link
Author

At the very least it would be great to know what file in the extension tells VSCode how to run black. Tell me that and I will fix this myself, since nobody else seems to care too much.

@Holt59
Copy link

Holt59 commented Sep 27, 2020

I have the same issue. Looking at the output console, I see this:

I:\Languages\Python\envs\myenv\Scripts\python.exe "c:/Users/XXX/.vscode/extensions/ms-python.python-2020.9.111407/pythonFiles/pyvsc-run-isolated.py" black --diff --quiet i:\Projects\my-project\main.py
cwd: i:\Projects\my-project

When running black directly on the command line with --diff --quiet or using the above command, I get the expected output from black.

I want to add that this happens on project where everything was working before, without any changes to the virtual environment, and thus to the black version, so this is most likely due to a recent update.

@CodePidgy
Copy link
Author

CodePidgy commented Sep 27, 2020

Thank you, I'm so glad to see I'm not alone. I'm thinking for a temporary fix we could find the file that tells VSCode to give black the --diff --quiet args and remove them, then it would start working again in theory.

@CodePidgy
Copy link
Author

@karthiknadig I would like to add the "needs PR" label to this please, as I've decided to do it myself

@karthiknadig
Copy link
Member

karthiknadig commented Sep 27, 2020

@DRACL10N We investigate issues in order based on priority and severity, which includes the impact it has on your ability to use the extension to do productive work, and the number of people affected. If other users come forward and leave a comment demonstrating they are seeing/reproducing the problem then we will raise this issue's priority.

VSCode to give black the --diff --quiet args and remove them, then it would start working again in theory.

The way formatting works with VS Code is we use --diff to generate text edits. These are then sent to VS Code Editor to apply those edits. This allows you to use editor features such like undo/redo etc. If you get rid of --diff then black will attempt to format the file in place. This will mean that VS Code does not know about those edits, and you will need to reload the file for VS Code to get the formatted file. Note that nothing has changed in this part of the code for a while.

I believe the issue was caused by this change: 23725ab . I have already reverted this (#14108) in main (last week), and this should be out in the bug fix release (probably this week).

@CodePidgy
Copy link
Author

Thank you

@karthiknadig karthiknadig changed the title Black not formatting Formatting fails to update files due to path quoting issues Sep 28, 2020
@CodePidgy
Copy link
Author

Does this bug effect Pylint as well?

@karthiknadig
Copy link
Member

pylint it depends. If you are using Microsoft language server or Pylance, you will not see pylint results (see #7314).

The formatting issue should be addressed in the latest version 2020.9.112786.

@CodePidgy
Copy link
Author

CodePidgy commented Oct 1, 2020

All is well, black and pylint are working. Thank you.

@ghost ghost removed the triage label Oct 1, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 6, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue identified by VS Code Team member as probable bug
Projects
None yet
Development

No branches or pull requests

3 participants