-
Notifications
You must be signed in to change notification settings - Fork 9
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
format Python files using black extension #669
Conversation
@@ -34,6 +22,7 @@ | |||
"eamodio.gitlens", | |||
"mhutchie.git-graph", | |||
"ms-python.python", | |||
"ms-python.black-formatter", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the difference between installing the extension and installing black
directly as part of the devcontainer build? My understanding is the black
formatting has already been working for a while now...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
black
is installed as a package, but wasn't actually being run from the editor. The extension does the latter. Steps to reproduce, without this pull request:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Weird. Can you confirm you don't have the black
extension installed? @machikoyasuda @angela-tran Do you get formatting on save, or no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mind trying rebuilding on this branch? If that works for you all, mind if we add the extension, even if it only makes a difference for me (for some reason)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are some troubleshooting tips here: https://code.visualstudio.com/docs/python/editing#_troubleshooting-formatting
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can also rebuild on your branch and make sure that having the extension would be ok
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I followed these steps:
- Modify a Python file in a way that should be undone with formatting (adding whitespace or whatever).
- Save — the file doesn't change.
- From the command palette, run
Format Document
. - I get a different dialog
When I click "Configure" and choose "Black Formatter", this is added to .vscode/settings.json
, and code is formatted on save:
"[python]": {
"editor.defaultFormatter": "ms-python.black-formatter"
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Asked for clarification: microsoft/vscode-black-formatter#82
Let's remove |
3f98fa5
to
e399fc0
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good gracious. Asked in microsoft/vscode-black-formatter#82 (comment). Does format on save work after you click |
Going back to draft while this is sorted out to remove from the review queue. |
e399fc0
to
edf08b8
Compare
Split this pull request into two to hopefully allow the other changes to get in. How are we feeling about this pull request? The |
842c9e1
to
bd465e3
Compare
The existing setup wasn't working for me — possibly because my global VSCode settings expect the black extension — so switched to that here.
edf08b8
to
5b23513
Compare
@@ -8,10 +8,11 @@ | |||
"files.insertFinalNewline": true, | |||
"files.trimFinalNewlines": true, | |||
"files.trimTrailingWhitespace": true, | |||
// https://github.com/microsoft/vscode-black-formatter/issues/82#issuecomment-1155492426 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On second thought, since I got formatting Python on save to work without the extra extension, this doesn't add value, and having to |
This does a few things:Sets the default formatter to be Prettier, which will also apply it to things like Markdown.Formats on save by default, which is fine because formatting HTML is still disabled, protecting the Jinja templates.Formats the settings files (with Prettier).The rest has been moved to #746.