question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Log error if YAPF formatting fails

See original GitHub issue

I 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:open
  • Created 3 years ago
  • Comments:17

github_iconTop GitHub Comments

2reactions
Spenhouetcommented, Apr 6, 2022

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.

2reactions
Triquetracommented, Apr 26, 2021

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to debug the error message from a yapf formatting task?
I recently inherited a code base and am in the process of using yapf (and indirectly lib2to3) to format the code base. When...
Read more >
Fix issues failing CI pipeline · e892df58dc - drydock - OpenDev
Run codebase through YAPF for formatting - Add tox configuration for yapf and pep8 ... ctx.fail('URL must specify a scheme and hostname, optionally...
Read more >
Google Python Style Guide
Many teams use the yapf auto-formatter to avoid arguing over formatting. ... Easy to miss error cases when making library calls.
Read more >
black · PyPI
If you want to format Jupyter Notebooks, install with pip install ... Remove logging from internal blib2to3 library since it regularly emits error...
Read more >
Settings Reference for Python - Visual Studio Code
logging.level, error, Specifies the level of logging to be performed by the ... that the code may fail at runtime when using this...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found