如何编写pep8配置(pep8.rc)文件?

问题描述 投票:22回答:2

我找到了pep8的文档但是无法理解如何编写这些文档。我甚至找不到任何除了设置max-line-length和ignore之外的选项的例子。

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

  • 启用show source
  • 启用统计
  • 启用计数
  • 排除目录(例如,./random

有人可以回答一个例子或链接到一个?

python pep8 pep
2个回答
29
投票

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

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

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



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
© www.soinside.com 2019 - 2024. All rights reserved.