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.

yapf formatting fails due to wrong command (--diff instead of --in-place)

See original GitHub issue

Bug: Notebook Editor, Interactive Window, Editor cells

Steps to cause the bug to occur

  1. Configure yapf as python formatter, turn on autoformat on save
  2. save a file (or format a document)

Actual behavior

Nothing happens, no error message in Python console

Expected behavior

Format the code

Details

Python console shows this command: /usr/local/bin/python3 ~/.vscode-server/extensions/ms-python.python-2020.5.86806/pythonFiles/pyvsc-run-isolated.py yapf --diff ~/test.py

When I run this command in the console, it only prints the diff. Instead the command should be /usr/local/bin/python3 ~/.vscode-server/extensions/ms-python.python-2020.5.86806/pythonFiles/pyvsc-run-isolated.py yapf -i ~/test.py

My understanding of yapf is that it only writes files if passed with the “-i” (–in-place) flag. Unfortunately, I can’t add this as additional parameter because --diff and -i are incompatible. How I can remove the addition of the --diff flag?

Also tested with and without passing --style="/home/ubuntu/setup.cfg"

[yapf]
based_on_style = pep8
column_limit = 100

settings.json:

{
    "python.linting.pylintEnabled": true,
    "python.formatting.provider": "yapf",
    "editor.formatOnSave": true
}

Your Jupyter and/or Python environment

Please provide as much info as you readily know

  • Jupyter server running: remote
  • Extension version: 2020.6.88468
  • VS Code version: 1.46.0
  • Setting python.jediEnabled: true
  • Setting python.languageServer: Jedi
  • Python and/or Anaconda version: Python 3.8.2
  • OS: Ubuntu 18.04 LTS

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
nlarusstonecommented, Aug 27, 2020

Can we reopen this? I’m experiencing the same issue. If i provide a style file as an argument, then nothing gets reformatted, but if I remove it then it autoreformats. Here are the two commands that are generated:

(Doesn’t work)

yapf --style style.yapf --diff ~/<PATH_TO_CODE>

(Formats the code, but not according to my custom settings)

yapf --diff ~/<PATH_TO_CODE>

This is recent (in the past few months) and seems like a bug to me

0reactions
karthiknadigcommented, Aug 27, 2020

@nlarusstone created a separate issue for your scenario.

Read more comments on GitHub >

github_iconTop Results From Across the Web

how to apply yapf to every python file under a directory?
The first problem is that wildcard expansion happens in the shell, before the command line even executes. When you run: somecommand *.py.
Read more >
Diff - platform/external/yapf - Google Git
This + can and does lead to non-stable formatting, where yapf will reformat the same + code in different ways. +### Fixed +-...
Read more >
Unable to run python formater (Are the instructions out of date?)
I tried both the tox and yapf instructions on the python tips page <https://cwiki.apache.org/confluence/display/BEAM/Python+Tips#PythonTips-Formatting>.
Read more >
Beginners Guide to Auto Formatting - DEV Community ‍ ‍
-i or --in-place flag make changes to files in place, and -vv or --verbose is for verbose messages. ... yapf allows you to...
Read more >
Python Coding Standards - Developer Documentation
Use black to format Python code with the configuration in the ... This will in place format any files with the .py extension...
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