Mechanism for automatic lint check with flake8 when committing python code

background

I want to lint check at the time of git commit so that I can not commit if the check does not pass. I didn't want to do automatic formatting this time, so I just did a lint check. By the way, if you want to lint check + automatic format, this area → Execute formatter at pre-commit

manner

Install pre-commit + flake8

cd $GIT_PROJECT
pipenv install pre-commit
pipenv install flake8

Create a config file for pre-commit .pre-commit-config.yaml

repos:
  - repo: https://gitlab.com/PyCQA/flake8
    rev: master
    hooks:
    - id: flake8

Create a config file for .flake8 .flake8

[flake8]
ignore = E501 #Set the number of characters check per line to ignore
; exclude = tests/*
max-complexity = 10

Generate a script for .git/hook/pre-commit

pre-commit install

This completes the pre-commit settings. At this point, you can put in a mechanism that each developer can format.

For example, in the case of VS Code, the following article will be helpful ↓ Introduce flake8 instead of pylint in VS Code Python development environment and set automatic formatting

Recommended Posts

Mechanism for automatic lint check with flake8 when committing python code
Check the code with flake8
Move THORLABS automatic stage with Python [for research]
Specific sample code for working with SQLite3 in Python
VS Code settings for developing in Python with completion
Tips for speeding up python code correctly with numba
Domain check with Python
Check version with python
[Python] Create a screen for HTTP status code 403/404/500 with Django
Python with VS Code (Windows 10)
Check python coverage with pytest-cov
Python code memo for yourself
Debug Python with VS Code
Error when playing with python
[Python] Sample code for Python grammar
Document Python code with Doxygen
Be careful of LANG for UnicodeEncodeError when printing Japanese with Python 3
[Let's play with Python] Aiming for automatic sentence generation ~ Completion of automatic sentence generation ~
Check the memory protection of linux kerne with the code for ARM
A memo for when pip3 is installed with python2.7 for some reason
Check for memory leaks in Python
Check for external commands in python
Check the behavior when assigning Python
Getting Started with Python for PHPer-Classes
Check python code styles using pep8
When matplotlib doesn't work with python2.7
Getting Started with Python for PHPer-Functions
When using MeCab with virtualenv python
Precautions when using six with Python 2.5
[VS Code] ~ Tips when using python ~
Install python with mac vs code
[Python] Format when to_csv with pandas
Prepare a Python virtual environment for your project with venv with VS Code
[Let's play with Python] Aiming for automatic sentence generation ~ Perform morphological analysis ~
Impressions and memorandums when working with VS code for the first time
Error due to UnicodeDecodeError when reading CSV file with Python [For beginners]