我找到了PEP8文档,但是无法理解如何编写它们。除了设置max-line-length和ignore之外,我甚至找不到任何其他选项的示例。
我正在尝试编写一个 .pep8.rc 文件,在其中需要执行以下操作:
- 启用show source
- 启用statistics
- 启用count
- 排除一个目录(例如 ./random)
有人能提供一个示例或链接吗?
首选方法是在项目的顶层使用 setup.cfg
文件(.cfg 的语法与 .ini 文件 相同),其中应包含一个 [pep8]
部分。例如:
[pep8]
ignore = E226,E302,E41
max-line-length = 160
注意:错误代码在pep8文档中定义。
[pep8]
部分。[flake8]
部分。[yapf]
部分。不幸的是,Andy Hayden的答案对于pytest
/pytest-pep8
/flake8
无效。
为此,您必须使用以下任一选项:
# content of setup.cfg
[pytest]
pep8maxlinelength = 99
或者
[pytest]
max-line-length=99
奇怪的是,以下内容无法正常工作
[tool:pytest]
max-line-length=99
添加
[flake8]
max-line-length=99
为了避免混淆,他们将pep8重命名为pycodestyle。
您可以使用以下方式创建setup.cfg文件:
[pycodestyle]
ignore = E226,E302,E41
max-line-length = 119
exclude =
tests/
docs/
关于错误代码,您可以阅读此文档。
pep8maxlinelength
(来源) - Martin Thoma