I’m working on an Django project. I want to add flake8 to check my django codes today, and make code changes must be checked before commit.
Here’s what I did.
I found all my needed from the official Flake8 document, and below is what I did:
- must check before Git commit
- custome flake8 config file, due to django allow line length longer than 80 characters.
Use pip can install flake8 quickly by:
pip install flake8
Create a file named
.flake8 in Django’s root directory, the
.flake8 will be used when call flake8 to check.
My custome config file is like below:
My intention is:
- ignore D203
- exclude files include .git, pycache, old, build, and migrations. All the exclude is not python files, or files not need to be checked
- set max-complexity to 10
- expand man line lengh to 119, PEP8 only allow 80 length
Flake8 can be called by
I want to ask git check all my code changes to satisfy Flake8 standards, below command is ask git to do so:
flake8 --install-hook git # install git hook