【问题标题】:How to write a pep8 configuration (pep8.rc) file?如何编写 pep8 配置(pep8.rc)文件?
【发布时间】:2015-07-30 00:41:34
【问题描述】:

我找到了 pep8 的文档,但无法理解如何编写这些文档。除了设置 max-line-length 和忽略之外,我什至找不到任何带有选项的示例。

我正在尝试编写一个.pep8.rc 文件,其中我需要执行以下操作:

  • 启用显示源
  • 启用统计
  • 启用计数
  • 排除目录(例如./random

有人可以用示例或链接来回答吗?

【问题讨论】:

    标签: python pep8 pep


    【解决方案1】:

    首选方法是在项目的顶层使用setup.cfg(.cfg 与.ini file 具有相同的语法),其中应包含[pep8] 部分。例如:

    [pep8]
    ignore = E226,E302,E41
    max-line-length = 160
    

    注意:错误代码在pep8 docs中定义。


    • autopep8 找到与 pep8 相同的 [pep8] 部分。
    • flake8 在 setup.cfg 中需要一个 [flake8] section
    • yapf 在 setup.cfg 中查找 [yapf] section

    【讨论】:

    • NOT 是否与 pytest 一起工作!什么是pep8maxlinelength (source)
    【解决方案2】:

    遗憾的是,Andy Hayden 的回答不适用于 pytest / pytest-pep8 / flake8

    pytest-pep8

    为此,您必须使用任一

    # content of setup.cfg
    [pytest]
    pep8maxlinelength = 99
    

    [pytest]
    max-line-length=99
    

    奇怪的是,以下方法不起作用

    [tool:pytest]
    max-line-length=99
    

    pytest-flake8

    添加

     [flake8]
     max-line-length=99
    

    【讨论】:

      【解决方案3】:

      他们将 pep8 重命名为 pycodestyle 以避免混淆。

      您可以使用以下命令创建 setup.cfg 文件:

      [pycodestyle]
      ignore = E226,E302,E41
      max-line-length = 119
      exclude =
          tests/
          docs/
      

      有关错误代码,您可以阅读this 文档。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2013-07-24
        • 2017-11-20
        • 2011-04-08
        • 2014-01-27
        • 2013-08-28
        • 2010-12-24
        • 2017-12-30
        相关资源
        最近更新 更多