EeyoreLee / vscode-extension-yapf

Vscode formatter extension support for python files using `yapf`.
MIT License
18 stars 5 forks source link
formatter vscode vscode-extension yapf

Vscode formatter extension support for python files using yapf

A formatter extension with support for python files and notebook cell. Feel free to open an issue to tell me what feature else do you need since it's a preview version.
Note:

Quick Start

Setting the following can enable this formatter quickly.

  "[python]": {
    "editor.formatOnSaveMode": "file",
    "editor.formatOnSave": true,
    "editor.defaultFormatter": "eeyore.yapf",
    "editor.formatOnType": false
  }

Usage

Address crash for python3.7 or lower

Use yapf.interpreter property to select a python interpreter that 3.8 or higher to run this tool by subprocess

file mode & modifications mode

Choose the mode by the following

Format for notebook

Set your own yapf style

Note this setting has to be in the global scope of settings.json, not in a [python] block.

Add extra magic function for jupyter

This extension supports the following magic functions by default

"capture",
"prun",
"pypy",
"python",
"python3",
"time",
"timeit"

Other magic functions like %matplotlib inline, you need to add it to the yapf.cellMagics property.

"yapf.cellMagics": ["matplotlib inline"]