19.3.2. Using Formatters
Python
For Python code we use yapf
as formatter with these settings:
[style]
based_on_style = pep8
column_limit = 80
The default .style.yapf
yapf
style file can be found on GitHub Gist or directly downloaded in your current directory by executing:
wget https://gist.githubusercontent.com/lennartalff/42dc02ee01ced47bfb0f75d715e5dcf9/raw/da9d31abbf27d1d71b24a25dbe1c840506a17bfb/.style.yapf
Note
The downloaded file is named .style.yapf
and is therefore hidden. To show up in command line use ls -a
or hit Ctrl + H in your GUI filebrowser.
To run yapf
via the commandline and show the differences on formatting it suggests enter your project’s directory and enter:
yapf --diff --recursive .
If no output shows up this means all the Python files are already formatted according to the style settings in .style.yapf
.
To apply changes on all files run:
yapf -i --recursive .
Hint
A more detailed description on how to use yapf
can be found in its README.