pyproject-flake8
pyproject-flake8 (`pflake8`) is a wrapper that monkey-patches Flake8 to enable configuration through `pyproject.toml`. It addresses Flake8's lack of native `pyproject.toml` support by providing a minimal solution to consolidate project configuration. The current version is 7.0.0, and its release cycle is closely tied to the `flake8` releases it supports, with explicit version pinning for stability.
Warnings
- breaking This library functions by monkey-patching `flake8` and Python's `configparser` module. Significant internal changes in `flake8` or Python itself (especially `configparser`) can lead to unexpected breakage or incompatibility between `pyproject-flake8` versions and its dependencies.
- breaking Starting with version 5.0.4, `pyproject-flake8` explicitly pins its dependency to a specific `flake8` version. For version 7.0.0, it requires `flake8==7.0.0`. This means users using different `flake8` versions might encounter dependency conflicts or require `pyproject-flake8` versions compatible with their `flake8`.
- gotcha To use `pyproject-flake8`, you must invoke the `pflake8` command-line executable, not the standard `flake8` command. Running `flake8` directly will not pick up the `pyproject.toml` configuration provided by this wrapper.
- gotcha Flake8 configuration in `pyproject.toml` must be placed under the `[tool.flake8]` section. Placing it directly under `[flake8]` or in other sections will cause it to be ignored by `pflake8`.
- gotcha There are other packages, such as `flake8-pyproject`, which also aim to provide `pyproject.toml` support for Flake8 but use a different implementation (as a Flake8 plugin). `flake8-pyproject` typically allows running `flake8` directly, whereas `pyproject-flake8` requires `pflake8`. Understand the distinction to choose the correct tool for your needs.
Install
-
pip install pyproject-flake8
Imports
- pflake8
This library is primarily used as a command-line executable named `pflake8`, not typically imported as a Python module for direct use, as it monkey-patches `flake8` internally.
Quickstart
# 1. Install pyproject-flake8 pip install pyproject-flake8 # 2. Create a pyproject.toml file in your project root # (Example content below) # [tool.flake8] # max-line-length = 88 # extend-ignore = ["E203", "W503"] # exclude = ["venv", ".git", "__pycache__"] # 3. Run pflake8 instead of flake8 pflake8 your_module.py your_package/