Skip to content

Code formatting with YAPF

Thomas Reisser edited this page Apr 5, 2022 · 1 revision

Using YAPF (yet another Python formatter) to format the code (manually)

Install yapf

pip install yapf

Configuration of style and excluded files

Create a file called .style.yapf where you can define some settings. We use for now:

[style]
based_on_style = pep8
column_limit = 120

Create a file called .yapfignore where you can (similarly to .gitignore) set folders or files that should be excluded:

docs/**
docsource/**

Running the code formatting

Just do the following in the root directoy:

yapf -rip .

where -r is for recursive mode, -i is for in-place, i.e. that the files are overwritten and -p is for parallel, so that it runs much faster.

If you want to see which files have been changed, you can also add -vv as an extra argument for verbose mode.

Clone this wiki locally