Default Formatter
Visual Studio Code is free and available on your favorite platform - Linux, macOS, and Windows. Download Visual Studio Code to experience a redefined code editor, optimized for building and debugging modern web and cloud applications. Python support is presently available only on Visual Studio for Windows; on Mac and Linux, Python support is available through Visual Studio Code. Download and run the latest Visual Studio installer for Windows (Python support is present in release 15.2 and later).
Code formatting is supported using either one of yapf or autopep8.
The default code format provider is autopep8.
Auto Formatting
Formatting the source code as and when you save the contents of the file is supported.
Enabling this requires configuring the setting 'editor.formatOnSave': true
as identified here.
Paths
All samples provided here are for windows.
However Mac/Linux paths are also supported.
AutoPep8
You can configure the format provider by changing a setting in the User or Workspace settings file as follows:
Installing autopep8
Custom Path
This is generally unnecessary. As the Extension will resolve the path to the formatter based on Python executable being used or configured in python.pythonPath of settings.json. If this cannot be found, then the formatter will be resolved based on the current environment Path settings.
If this is not the case or you wish to use another version of autopep8, all you need to do is configure the path as follows either in the User or Workspace settings file:
Yapf
Visual Studio For Mac
You can configure the format provider by changing a setting in the User or Workspace settings file as follows:
Custom Path
This is generally unnecessary. As the Extension will resolve the path to the formatter based on Python executable being used or configured in python.pythonPath of settings.json. If this cannot be found, then the formatter will be resolved based on the current environment Path settings.
If this is not the case or you wish to use another version of yapf, all you need to do is configure the path as follows either in the User or Workspace settings file:
Custom arguments to Yapf
Visual Studio Code
Custom arguments can be passed into yaps by configuring the settings in the User or Workspace settings as follows:
Installing Yapf
Python Visual Studio Code Mac Os
pip install yapf