python3 formatting with black

Date: 2019/09/02 (initial publish), 2021/07/16 (last update)

Source: en/note-00004.md

Previous Post Top Next Post

TOC

I see formatting consistency provided by the black command helps me.

The black is available as Debian package and its upstream is at https://github.com/psf/black

Lint tools before black

These are basic lint tools before black.

Install black

 $ sudo apt install python3-black

Use black

 $ black a-python-code-directory/

or

 $ black a-python-code-file.py

Skip Lint prigram

Line with #NOQA at the end are skipped by pycodestyle for PEP-8 lint.

Lines between # fmt: off and # fmt: on are skipped by the black.

Make black to work with other tools

Adding followings to pyproject.toml may be useful.

[flake8]
max-line-length = 88
select = C,E,F,W,B,B950
ignore = E203,W503,W504

[tool.isort]
include_trailing_comma = true
line_length = 88
multi_line_output = 3

Here:

Other programs

Previous Post Top Next Post