Skip to main content

Flake8-pyproject (flake8p)

Runs Flake8 with configuration from pyproject.toml

Flake8 cannot be configured via pyproject.toml, even though virtually all other Python dev tools have adopted it as the central location for project configuration. The discussion of the original proposal (#234) was closed as "too heated", subsequent feature and pull requests were marked as "spam" (#1332, #1421, #1431, #1447, #1501).

Flake8-pyproject also has bad manners and force-feeds Flake8 the spam it so despises.

It is inspired by pyproject-Flake8, though the code was rewritten from scratch and a test suite was added to make maintenance easier. You may however consider using the original project instead, or any of the other alternatives mentioned in issue #2.

Usage

Say your Flake8 configuration in .flake8 (or in tox.ini, or setup.cfg) is this:

[flake8]
ignore = E231, E241
per-file-ignores =
    __init__.py:F401
max-line-length = 88
count = true

Copy that [flake8] section to pyproject.toml, rename it as [tool.flake8], and convert the key–value pairs to the TOML format:

[tool.flake8]
ignore = ['E231', 'E241']
per-file-ignores = [
    '__init__.py:F401',
]
max-line-length = 88
count = true

From then on run flake8p instead of flake8 to lint the code, from within the same folder that pyproject.toml is in.

Implementation

Flake8 uses RawConfigParser from the standard library to parse its configuration files, and therefore expects them to have the INI format.

This library adds pyproject.toml to Flake8's list of acceptable configuration files and monkey-patches Flake8's RawConfigParser class definition so that, when pyproject.toml is being read, the format is converted from TOML to INI on the fly. TOML parsing is handled by Tomli, which will be part of the standard library as of Python 3.11 (PEP 680).

A few very simple integration tests round out the package, making sure that any one of the possible configuration files are in fact accepted.

Pre-commit hook

To have flake8p run on every git commit, add the following to your project's pre-commit configuration .pre-commit-config.yaml:

-   repo: https://github.com/john-hen/Flake8-pyproject
    rev: 1.0.1
    hooks:
    -   id: Flake8-pyproject

Change the revision to whatever is the latest release version.

Release files for Flake8-pyproject 1.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distribution (wheel)

Table of built distributions (wheels) for Flake8-pyproject 1.0.1
File Interpreter ABI Platform
flake8_pyproject-1.0.1-py3-none-any.whl Python 3 none any Details

Release files / flake8_pyproject-1.0.1-py3-none-any.whl

Download URL flake8_pyproject-1.0.1-py3-none-any.whl
Size 5.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
cf57a7b812fdf1e9e64a065a722521d8c761a5989e3aaa1c6d400e2e1eddc477
BLAKE2b-256 checksum
How to use checksums
3f4d7ad235602a2f0f04c0bfa2ec4ca96340a59693e066ad1be3ca09c71097bf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-requests/2.28.1

Release history Release notifications | RSS feed

1.2.4

1 release file

1.2.3

1 release file

1.2.2

1 release file

1.2.1

1 release file

1.2.0

1 release file

1.1.0

1 release file

This release

1.0.1 This release

1 release file

1.0.0

1 release file

0.9.1

1 release file

0.9.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page