Wing can automatically reformat code to be compliant with the PEP 8 Style Guide for Python Code.

Manual PEP 8 Reformatting

The Source > PEP 8 menu group contains items for reformatting the current selection or current file to be PEP 8 compliant. A single Undo will undo the reformatting operation.

Note that reformatting large files may take several minutes, and Wing will lock the file so it cannot be edited during that time. The amount of time spent in reformatting a file is limited to the number of seconds specified with the Editor > PEP 8 > Reformatting Timeout preference. The default is set purposely low to avoid leaving an editor locked for a long period of time.

Reformatting of selections is not time-limited, so very large selections may lock up the IDE until the reformatting operation completes.

Automatic PEP 8 Reformatting

PEP 8 formatting may be applied automatically character by character, as you type, through Wing Pro's auto-editing facility, by enabling the Editor > Auto-Editing > Auto-Enter Spaces and Editor > Auto-Editing > Enforce PEP 8 Style Spacing preferences.

Alternatively, this may be done by auto-formatting edited lines after the caret leaves the line, or by reformatting whole files as they are saved to disk. This is enabled with the Editor > PEP 8 > Auto-Reformat for PEP 8 preference. The choices are:

PEP 8 Reformatting Options

Several options for PEP 8 formatting are provided in the Editor > PEP 8 preferences group:

Using Other PEP 8 Reformatters

Wing uses autopep8 to implement PEP 8 reformatting. To use other PEP 8 reformatters like YAPF and Black, use the OS Commands tool to set up a command line that converts the file in place. The command line may contains %s for the current file name. After conversion on disk, Wing will automatically reload the file into the editor.

For YAPF:

yapf -i %s

For Black:

black %s

OS Commands may be given a key binding, to make them easier to invoke for the current file. However, there is currently no way to use YAPF or Black with the automatic PEP 8 reformatting features described above.