Specify per-file-ignores with pyproject.toml and flake8

16.1k Views Asked by At

I am using flake8 (with flakehell but that should not interfere) and keep its configuration in a pyproject.toml file. I want to add a per-file-ignores config but nothing works and there is no documentation on how it is supposed to be formatted in a toml file.

Flake8 docs show only the 'native' config file format:

per-file-ignores =
    project/__init__.py:F401
    setup.py:E121
    other_project/*:W9

There is no description / example for pyproject.toml.

I tried:

per-file-ignores=["file1.py:W0621", "file2.py:W0621"]

and

per-file-ignores={"file1.py" = "W0621", "file2.py" = "W0621"}

both of which silently fail and have no effect (the warning is still raised).

What is the proper syntax for per-file-ignores setting in flake8/flakehell while using pyproject.toml?

2

There are 2 best solutions below

8
On BEST ANSWER

flake8 does not have support for pyproject.toml, only .flake8, setup.cfg, and tox.ini


disclaimer: I am the flake8 maintainer

4
On

Currently, pyproject-flake8 enables you to write your flake8 settings on pyproject.toml like this.

# pyproject.toml
[tool.flake8]
    exclude = ".venv"
    max-complexity = 10
    max-line-length = 100
    extend-ignore = """
        W503,
        E203,
        E701,
    """
    per-file-ignores = """
        __init__.py: F401
        ./src/*: E402
    """