[Python] Migrate from yapf to black#33138
Conversation
c13dcbb to
e00ba8f
Compare
|
Sorry, had to force-push to preserve the commit structure. |
|
Yea, sorry, force pushes will have to happen in this PR. |
|
In both cases I added more autogenerated files to the exclude list, re-ran black, and replaced the |
|
Per @ctiller's recommendation, we're postponing this merge until after the end of the fixit. Then I'll sync it with master, and redo the code generation. |
| src_paths = [ | ||
| "examples/python/data_transmission", | ||
| "examples/python/async_streaming", | ||
| "tools/run_tests/xds_k8s_test_driver", | ||
| "src/python/grpcio_tests", | ||
| "tools/run_tests", | ||
| ] |
There was a problem hiding this comment.
I guess this part it copied from tools/distrib/isort_code.sh, @gnossen do you know why only those paths are included?
There was a problem hiding this comment.
For the examples, I think the answer is basically "Lidi wrote these examples." I'm surprised that the implementation directory is not included here, but if it never was to begin with, I'm fine with leaving this the way it is.
There was a problem hiding this comment.
Yea, that's weird. I just translated all the inline arguments to isort into a nice and readable config as is. The only change to isort settings is to use black profile, for obvious reasons.
| else | ||
| readonly MODE="--in-place" | ||
| readonly VERBOSE="--verbose" # print out file names while processing | ||
| readonly MODE="" |
There was a problem hiding this comment.
What will this default mode do?
There was a problem hiding this comment.
Black in the default mode (no args) will rewrite the code in place. yapf needed --in-place to do that, otherwise it'd just print the formatted file contents to the stdout.
gnossen
left a comment
There was a problem hiding this comment.
Huge thanks for this. We've been wanting this for literally years.
| src_paths = [ | ||
| "examples/python/data_transmission", | ||
| "examples/python/async_streaming", | ||
| "tools/run_tests/xds_k8s_test_driver", | ||
| "src/python/grpcio_tests", | ||
| "tools/run_tests", | ||
| ] |
There was a problem hiding this comment.
For the examples, I think the answer is basically "Lidi wrote these examples." I'm surprised that the implementation directory is not included here, but if it never was to begin with, I'm fine with leaving this the way it is.
|
Just a note: The last force push was regenerating the code after with target-version updated to py37...py311. It had no effect on the generated code (and that's OK). |
|
PSM Interop (using reformatted framework and rebuilding the test images from this branch): |
|
@XuanWang-Amos Note I made a small change to I just used the typehint notation made for this case - putting the class declared later in the same file in quotes. |
PR #33138 is the Large Scale Change in which python style is changed from yapf to black. Nearly all python files were reformatted. This PR configures git clients supporting `.git-blame-ignore-revs` feature to show the original author in `git blame`. Details: https://black.readthedocs.io/en/stable/guides/introducing_black_to_your_project.html GitHub uses this feature by default: https://docs.github.com/en/repositories/working-with-files/using-files/viewing-a-file#ignore-commits-in-the-blame-view Local git clients can enable this feature with `git config blame.ignoreRevsFile .git-blame-ignore-revs`.
Reverts grpc#33385 Temporary revert to unblock grpc#33138
- Switched from yapf to black - Reconfigure isort for black - Resolve black/pylint idiosyncrasies Note: I used `--experimental-string-processing` because black was producing "implicit string concatenation", similar to what described here: psf/black#1837. While currently this feature is experimental, it will be enabled by default: psf/black#2188. After running black with the new string processing so that the generated code merges these `"hello" " world"` strings concatenations, then I removed `--experimental-string-processing` for stability, and regenerated the code again. To the reviewer: don't even try to open "Files Changed" tab 😄 It's better to review commit-by-commit, and ignore `run black and isort`.
PR grpc#33138 is the Large Scale Change in which python style is changed from yapf to black. Nearly all python files were reformatted. This PR configures git clients supporting `.git-blame-ignore-revs` feature to show the original author in `git blame`. Details: https://black.readthedocs.io/en/stable/guides/introducing_black_to_your_project.html GitHub uses this feature by default: https://docs.github.com/en/repositories/working-with-files/using-files/viewing-a-file#ignore-commits-in-the-blame-view Local git clients can enable this feature with `git config blame.ignoreRevsFile .git-blame-ignore-revs`.
|
@sergiitk It would be good if the PR description contained info on what is the right command to run now (instead of |
|
@jtattermusch Sorry, this was a large PR, easy to miss stuff.
|
- Switched from yapf to black - Reconfigure isort for black - Resolve black/pylint idiosyncrasies Note: I used `--experimental-string-processing` because black was producing "implicit string concatenation", similar to what described here: psf/black#1837. While currently this feature is experimental, it will be enabled by default: psf/black#2188. After running black with the new string processing so that the generated code merges these `"hello" " world"` strings concatenations, then I removed `--experimental-string-processing` for stability, and regenerated the code again. To the reviewer: don't even try to open "Files Changed" tab 😄 It's better to review commit-by-commit, and ignore `run black and isort`.
Note: I used
--experimental-string-processingbecause black was producing "implicit string concatenation", similar to what described here: psf/black#1837. While currently this feature is experimental, it will be enabled by default: psf/black#2188. After running black with the new string processing so that the generated code merges these"hello" " world"strings concatenations, then I removed--experimental-string-processingfor stability, and regenerated the code again.To the reviewer: don't even try to open "Files Changed" tab 😄 It's better to review commit-by-commit, and ignore
run black and isort.