Git Product home page Git Product logo

vscode-extension-yapf's Introduction

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

  • Install yapf package from pip in following. This is optional but recommended way, else it will use the bundled yapf=0.40.2
pip install yapf
  • Select this fotmatter eeyore.yapf by adding the following to your vscode settings
  "[python]": {
    "editor.defaultFormatter": "eeyore.yapf"
  }
  • Enable format on save by adding the following
  "[python]": {
    "editor.formatOnSave": true
  }

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

  • Use file mode
  "[python]": {
    "editor.formatOnSaveMode": "file"
  }
  • Use modifications mode
  "[python]": {
    "editor.formatOnSaveMode": "modifications"
  }

Format for notebook

  • Format on cell execution
  "notebook.formatOnCellExecution": true
  • Format on save
  "notebook.formatOnSave.enabled": true

Set your own yapf style

  • Set style by the following vscode settings which is equal to yapf --style '{based_on_style: pep8, indent_width: 2}'
  "yapf.args": ["--style", "{based_on_style: pep8, indent_width: 2}"]
  • Use a style file, like .style.yapf, setup.cfg, pyproject.toml, ~/.config/yapf/style. For details, see google/yapf

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"]

vscode-extension-yapf's People

Contributors

dependabot[bot] avatar eeyorelee avatar j-kleemann avatar northwang-lucky avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.