27.15. Black Integration

Optionally, you can install Black, which provides automatic code formatting for Python code in accordance with PEP-8.

By default, CTRL+ALT+L runs the code formatting on a Python file, formatting and saving the file. You can change the keyboard shortcut in the “Shortcuts” section of MATE's preferences.

You can automatically format an edited Python file when saving it manually by enabling the Run On Save option.

The formatting uses the default settings for black. There are a few settings that black allows to configure, most notably the maximum line length, which defaults to 88 (the current de-facto standard). To change these settings, you can create a configuration file named pyproject.toml in the package root or in one of the subdirectories below which your Python files are located. For example, to change the maximum line length to 120 characters, you can use:

[tool.black]
line-length = 120
in your pyproject.toml file.