Skip to main content

Runs Flake8 with configuration from pyproject.toml.

Project description

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

First, move your Flake8 configuration to pyproject.toml. Then, optionally, add Flake8p as a git pre-commit hook.

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, so that the configuration in pyproject.toml will be used.

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

# your-project-root/.pre-commit-hooks.yaml
-   repo: https://github.com/john-hen/Flake8-pyproject
    rev: 0.9.0
    hooks:
    -   id: Flake8-pyproject

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

flake8_pyproject-1.0.0-py3-none-any.whl (5.3 kB view details)

Uploaded Python 3

File details

Details for the file flake8_pyproject-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for flake8_pyproject-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9dcbe0c40c34085b75105ad82bf3803931060f29d5821382a2906734ce13c5a7
MD5 2067b957335ba9b60c99deddf1487387
BLAKE2b-256 1d321553c2af5ccd67ddf17e84ef1d0a8a12120c908fcea72cdde5d666c17171

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page