【问题标题】:Specify per-file-ignores with pyproject.toml and flake8使用 pyproject.toml 和 flake8 指定每个文件忽略
【发布时间】:2021-02-05 11:44:34
【问题描述】:

我正在使用 flake8(带有 flakehell 但不应该干扰)并将其配置保存在 pyproject.toml 文件中。我想添加一个per-file-ignores 配置,但没有任何效果,也没有关于它应该如何在 toml 文件中格式化的文档。

Flake8 docs 仅显示“本机”配置文件格式:

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

pyproject.toml 没有描述/示例。

我试过了:

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

和

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

两者都静默失败并且没有效果(警告仍然出现)。

在使用 pyproject.toml 时,在 flake8/flakehell 中设置每个文件忽略设置的正确语法是什么?

【问题讨论】:

    标签: python configuration lint flake8


    【解决方案1】:

    flake8 不支持 pyproject.toml,只有.flake8、setup.cfg 和tox.ini


    免责声明:我是 flake8 的维护者

    【讨论】:

    • 非常感谢!我已经意识到 pyproject.toml 支持实际上来自 flakehell ......在我的情况下,我应该使用 flakehell Exceptions 语法。 flakehell.readthedocs.io/config.html Flakehell 本身不支持此特定设置。
    • @PiotrZakrzewski ,“异常语法”的效果如何?我试图有类似的东西:``` [tool.flakehell.exceptions."*/test/.py"] pydocstyle = ["-*"] ``` 但它没有排除传递的 glob 模式的特定插件:/ ...
    • 如果@siruku6 正确,这个答案是否需要更新?
    • @Zaffer nope,pyproject-flake8 不是官方的,也不支持,它甚至不能正常工作(并且会破坏每个版本,因为它使用私有的内部实现细节)
    【解决方案2】:

    目前,pyproject-flake8 允许您像这样在pyproject.toml 上写入 flake8 设置。

    # 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
        """
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-06-17
      • 1970-01-01
      • 2019-07-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-02-02
      • 1970-01-01
      相关资源
      最近更新 更多