Home > Article > Backend Development > Python code standardization tool Flake8
Writing code actually needs to be standardized, especially in the team; otherwise Google will not publish various coding standards. The familiar ones include Google C++ Style Guide, Google Python Style Guide, etc.
Are these specifications useful? It's useful but useless, unless you have a good brain and use the standards to your advantage while coding; otherwise we will eventually need a tool to do this. Fortunately, python has more than one tool to help us do this. Stop talking nonsense and get to the point.
Pylint
I have used it and it turned purple. I wonder who is so boring and makes the rules so rigid. Can we pythoners be happy? But if we don’t see rubyer, what does Matz advocate? Is there any Happy Coding? So I’ll leave it alone after using it, because I don’t need to be so perverted, no love~ If you want to install it, it’s very simple:
Pep8
As the name suggests, it comes from the Python community The famous PEP 8. Basically, just write the code and press this, but this is not perfect enough; the installation is as follows:
easy_install pep8 // maybe nedd root
Pyflakes
Python program passive detection tool, it is really passive , according to the author, it is faster and not powerful enough, but it is okay~
easy_install pyflakes // maybe nedd root
Flake8
The protagonist appears. This is what I recommend, but it does not affect other people's liking of pylint. In fact, this guy is a master, a package of the following three tools:
PyFlakes
Pep8
Ned Batchelder's McCabe script
Not to mention the benefits, the key is scalability, which is clearly stated here: https:/ /pypi.python.org/pypi/flake8/2.0. The installation is as follows:
easy_install flake8 // maybe nedd root
If you like Git like me, then you are also a pythoner, then there are benefits, write the following code into .git/hooks/pre-commit:
#!/usr/bin/env python
import sys
from flake8.hooks import git_hook
COMPLEXITY = 12
STRICT = True
The code is not explained, it is written in the official document It's clear: http://flake8.readthedocs.org/en/latest/vcs.html#git-hook. If your pre-commit script already has rules, that's fine, just call python in the shell.
If you also like vim
as one of the two major artifacts, vim naturally needs a plug-in to enjoy the above tools:
nvie/vim-flake8
vim-scripts/pylint.vim
See By the above list, you should know what I'm talking about. Yes, install it with vundle:
" Flake8 plugin for Vim.
Bundle 'nvie/vim-flake8'
" compiler plugin for python style checking tool .
Bundle 'vim-scripts/pylint.vim'
autocmd FileType python compiler pylint
If you really don’t know vundle, it’s really time to use her: https://github.com/gmarik /vundle. If you find all this troublesome, just use my vimrc, here:
git clone https://github.com/icocoa/icocoa-vimrc.git --recursive vimrc // icocoa is my another account in GitHub