Log error if YAPF formatting fails
See original GitHub issueI have YAPF installed and setup to format my python files in-place on save. However, sometimes it appears to run but it doesn’t format the code. Unfortunately I cannot seem to find a pattern of when it works or doesn’t work.
I see a notification on the bottom bar saying “formatting code with yapf” but the coed does not get formatted. I can also manually trigger the formatting with Ctrl+Shift+I and that does not work either (in the cases where it is also not formatting on save). If I run yapf from the command line on the file in question it works just fine.
I do not know if this is the same issue as https://github.com/microsoft/vscode-python/issues/4841 because none of the known failure criteria discussed there are true for me. I do not have a blank line at the top of my document, I do not have any syntax errors preventing the code from being interpreted, and I can run yapf manually from the command line without issue.
Here is my settings.json
{
"editor.formatOnSave": true,
"editor.renderWhitespace": "boundary",
"editor.rulers": [
95
],
"python.linting.pylintEnabled": false,
"python.linting.flake8Enabled": true,
"python.linting.enabled": true,
"python.formatting.provider": "yapf",
"python.pythonPath": "${env:HOME}/Envs/falkor/bin/python",
}
Extension version: 2020.5.86806 VS Code version: Code 1.45.1 (5763d909d5f12fe19f215cbfdd29a91c0fa9208a, 2020-05-14T08:27:22.494Z) OS version: Linux x64 5.3.0-59-generic
System Info
Item | Value |
---|---|
CPUs | Intel® Core™ i9-8950HK CPU @ 2.90GHz (12 x 3816) |
GPU Status | 2d_canvas: enabled flash_3d: enabled flash_stage3d: enabled flash_stage3d_baseline: enabled gpu_compositing: enabled multiple_raster_threads: enabled_on oop_rasterization: disabled_off protected_video_decode: unavailable_off rasterization: disabled_software skia_renderer: disabled_off_ok video_decode: unavailable_off viz_display_compositor: enabled_on viz_hit_test_surface_layer: disabled_off_ok webgl: enabled webgl2: enabled |
Load (avg) | 1, 2, 1 |
Memory (System) | 31.00GB (10.22GB free) |
Process Argv | ./ --no-sandbox |
Screen Reader | no |
VM | 0% |
DESKTOP_SESSION | ubuntu |
XDG_CURRENT_DESKTOP | Unity |
XDG_SESSION_DESKTOP | ubuntu |
XDG_SESSION_TYPE | x11 |
Issue Analytics
- State:
- Created 3 years ago
- Comments:17
Top GitHub Comments
Okay, I might have found our issue. We have a python file called “logging.py” which itself imported “logging.py” from the standard python lib. This cyclic dependency did not seem to make any issues until now but suddenly it seem that this killed the formatting with yapf. If I rename the file everything seems to work again.
Still not great that VS code is not outputting any error log what so ever.
I’m just leaving a note for others who might be encountering similar problems. On my system yapf was working on some files, but not on others. I had the yapf settings in pyproject.toml. Running the vscode generated command in the console showed that sometimes (but not always, apparently?) yapf complained that toml must be installed to use toml settings. After installing toml in my venv, the errors seem to have cleared up.