flake8 in Python

Содержание
Introduction
Install
Usage
Only on Changed Files
Related Articles

Introduction

Flake8 - is a tool that checks Python code for PEP8 compliance and some errors. It is essentially a wrapper for the following tools:

Installation

To install flake8 run the command

python -m pip install flake8

Collecting flake8 Using cached flake8-7.2.0-py2.py3-none-any.whl.metadata (3.8 kB) Collecting mccabe<0.8.0,>=0.7.0 (from flake8) Using cached mccabe-0.7.0-py2.py3-none-any.whl.metadata (5.0 kB) Collecting pycodestyle<2.14.0,>=2.13.0 (from flake8) Using cached pycodestyle-2.13.0-py2.py3-none-any.whl.metadata (4.5 kB) Collecting pyflakes<3.4.0,>=3.3.0 (from flake8) Using cached pyflakes-3.3.2-py2.py3-none-any.whl.metadata (3.5 kB) Using cached flake8-7.2.0-py2.py3-none-any.whl (57 kB) Using cached mccabe-0.7.0-py2.py3-none-any.whl (7.3 kB) Using cached pycodestyle-2.13.0-py2.py3-none-any.whl (31 kB) Using cached pyflakes-3.3.2-py2.py3-none-any.whl (63 kB) Installing collected packages: pyflakes, pycodestyle, mccabe, flake8 Successfully installed flake8-7.2.0 mccabe-0.7.0 pycodestyle-2.13.0 pyflakes-3.3.2

Example of usage

You can apply flake8 to a specific file or to a whole directory

python -m flake8 app/lib

.\app\lib\InfoPage.py:89:80: E501 line too long (270 > 79 characters) .\app\lib\InfoPage.py:75:1: E302 expected 2 blank lines, found 1 .\app\lib\local_keywords.py:95:1: W391 blank line at end of file

Apply to changed files only

To use flake8 against files that were not yet commited, including those in staging area

python -m flake8 $(git status -s | grep -E '\.py$' | cut -c 4-)

Article author: Andrei Olegovich

Похожие статьи
Basics
Python
Installation
OOP in Python
flake8
docstring
#!: Shebang
Objects
os
pathlib
flake8

Search this site

Subscribe to Telegram channel @aofeed to follow new articles and updates to old ones

Go to channel

@aofeed

Ask a question in the Telegram group

@aofeedchat

Contacts and cooperation:
I recommend our hosting beget.ru
Write to info@urn.su, info@aredel.com if you:
1. Want to write an article for our site or translate an article into your native language.
2. Want to place thematically relevant ads on the site.
3. Ads on my site pass maximum censorship. If you see an ad block unsuitable for school-age children, shocking or misleading - please contact us by e-mail
4. Found a mistake, inaccuracy, bug, etc. on the site. ... .......
5. Articles can be shared on social media by clicking a network icon: