Skip to content

Repository files navigation

flake8-toml-config

Configure flake8 via pyproject.toml. Supports local plugins.


This flake8 plugin adds support for loading the flake8 configuration from pyproject.toml files, including loading local plugins.

The plugin will automatically find a pyproject.toml file in the current working directory where flake8 is run from. It also overrides the --config CLI option so that a TOML file can be specified to load the config from:

flake8 --config custom.toml

flake8-toml-config will respect the --isolated flag.

Note that this plugin replaces flake8's built-in support for other config file formats. While the plugin is installed, config can only be read from TOML files.

Table of contents

Configuration translation

Below is an example of a flake8 configuration as it would appear in a .flake8 file:

[flake8]
max-line-length = 80
extend-select = B950
extend-ignore = E203,E501,E701

[flake8:local-plugins]
paths = ./assets/flake8
extension =
    CL1 = custom_repo_linter:Plugin1
    CL2 = custom_repo_linter:Plugin2
reporter =
    CR = custom_repo_reporter:Plugin

Below is the equivalent configuration, suitable for use in a pyproject.toml file. Note that the flake8:local-plugins section requires quotes in the TOML format:

[tool.flake8]
max-line-length = 80
extend-select = ["B950"]
extend-ignore = ["E203", "E501", "E701"]

[tool."flake8:local-plugins"]
paths = ["./assets/flake8"]
extension.CL1 = "custom_repo_linter:Plugin1"
extension.CL2 = "custom_repo_linter:Plugin2"
reporter.CR = "custom_repo_reporter:Plugin"

Alternatively, multi-line TOML strings can be used for clearer config parity:

# ...
[tool."flake8:local-plugins"]
paths = ["./assets/flake8"]
extension = """
    CL1 = custom_repo_linter:Plugin1
    CL2 = custom_repo_linter:Plugin2
"""
reporter = """
    CR = custom_repo_reporter:Plugin
"""

pipx usage

If flake8 is installed using pipx, you can inject this plugin:

pipx inject flake8 flake8-toml-config

pre-commit usage

Add this plugin as an additional dependency:

- repo: "https://github.com/pycqa/flake8"
  rev: "7.3.0"
  hooks:
    - id: "flake8"
      additional_dependencies:
        - "flake8-toml-config==1.0.0"

Note that the pre-commit autoupdate command, and pre-commit.ci, do not update additional dependencies. Consider using upadup to auto-update additional dependencies as needed.

About

Configure flake8 via `pyproject.toml`. Supports local plugins.

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages