fix: formatting .pyi files with black#14736
Merged
karthiknadig merged 4 commits intomicrosoft:mainfrom Nov 30, 2020
sbdchd:steve/fix-formatting-pyi-files-with-black
Merged
fix: formatting .pyi files with black#14736karthiknadig merged 4 commits intomicrosoft:mainfrom sbdchd:steve/fix-formatting-pyi-files-with-black
karthiknadig merged 4 commits intomicrosoft:mainfrom
sbdchd:steve/fix-formatting-pyi-files-with-black
Conversation
Black has different formatting depending on the file ending. When formatting a modified buffer or saving a file black will be run against a temp file that looks roughly like: ``` ./.venv/bin/black --diff --quiet ./queryset.pyi.26c0667c29728299036ec32a0f6f7729.tmp ``` The problem with this is that the ending is lost so black will default to using the `.py` formatting, even when it's a `.pyi` file. fixes: #13341
karthiknadig
requested changes
Nov 16, 2020
|
|
||
| const blackArgs = ['--diff', '--quiet']; | ||
|
|
||
| if (document.fileName.endsWith('.pyi')) { |
Member
There was a problem hiding this comment.
Suggested change
| if (document.fileName.endsWith('.pyi')) { | |
| if (path.extname(document.fileName) === 'pyi') { |
Comment on lines
+43
to
+46
|
|
||
| if (document.fileName.endsWith('.pyi')) { | ||
| blackArgs.push('--pyi'); | ||
| } |
Member
There was a problem hiding this comment.
[Not blocking] Alternatively, we could also handle the tmp case with a regex. I have not tested this thoroughly, but it should be able to handle most cases:
Suggested change
| if (document.fileName.endsWith('.pyi')) { | |
| blackArgs.push('--pyi'); | |
| } | |
| const ext = path.extname(document.fileName); | |
| const pyiTmpPattern = /\.pyi(\.[0-9a-fA-F]*\.tmp)?/; | |
| // Matches patterns like: | |
| // something.pyi.26c0667c29728299036ec32a0f6f7729.tmp | |
| // something.pyi | |
| // .pyi.26c0667c29728299036ec32a0f6f7729.tmp | |
| // .pyi | |
| // py.pyi | |
| // some.pyi.py <--- This is a odd case but we can eliminate it be checking ext === 'tmp' | |
| if (ext === 'pyi' || (ext === 'tmp' && pyiTmpPattern.test(document.fileName))) { | |
| blackArgs.push('--pyi'); | |
| } |
Co-authored-by: Karthik Nadig <kanadig@microsoft.com>
|
Kudos, SonarCloud Quality Gate passed!
|
karthiknadig
approved these changes
Nov 17, 2020
int19h
approved these changes
Nov 17, 2020
karthiknadig
approved these changes
Nov 30, 2020
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Black has different formatting depending on the file ending.
When formatting a modified buffer or saving a file black will be run
against a temp file that looks roughly like:
The problem with this is that the ending is lost so black will default
to using the
.pyformatting, even when it's a.pyifile.partially fixes #13341
Pull request represents a single change (i.e. not fixing disparate/unrelated things in a single PR).
Title summarizes what is changing.
Has a news entry file (remember to thank yourself!).
Appropriate comments and documentation strings in the code.Has sufficient logging.Has telemetry for enhancements.Unit tests & system/integration tests are added/updated.Seems the integration suite isn't being run currently:
vscode-python/src/test/format/extension.format.test.ts
Lines 43 to 47 in 2a62cf7
Test plan is updated as appropriate.package-lock.jsonhas been regenerated by runningnpm install(if dependencies have changed).The wiki is updated with any design decisions/details.