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
.
pycodestyle
(formerly calledpep8
)flake8
(bundle of:pycodestyle
+pyflakes
).
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:
- max-line-length per line
- Black default is 88 ch/line https://github.com/psf/black#line-length
- Ignore
E501
for line too long (82 > 79 characters)
- pep8 Warning / Error codes
E203
for https://github.com/psf/black#slicesW503
for https://github.com/psf/black#line-breaks--binary-operatorsW504
for line break after binary operator (default ignored)
Other programs
- isort is a Python utility / library to sort imports alphabetically, and automatically separated into sections.
- flake8-black is a
flake8
plugin for validating Python code style with the command line code formatting toolblack
.
Previous Post | Top | Next Post |