How to write a pep8 configuration (pep8.rc) file?

送分小仙女□ 提交于 2019-12-03 05:40:56

问题


I found the documentation for pep8 but wasn't able to understand how to write these. I couldn't even find any examples with options other than setting max-line-length and ignore.

I am trying to write a .pep8.rc file in which, among other things, I need to do the following:

  • enable show source
  • enable statistics
  • enable count
  • exclude a directory (say, for example ./random)

Can somebody answer with an example or link to one?


回答1:


The preferred way is to use a setup.cfg in the top-level of the project (.cfg has the same syntax as a .ini file), which should contain a [pep8] section. For example:

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

Note: the error codes are defined in the pep8 docs.


  • autopep8 find this same [pep8] section as pep8.
  • flake8 needs a [flake8] section in setup.cfg.
  • yapf looks for a [yapf] section in setup.cfg.



回答2:


Sadly, the answer from Andy Hayden does not work for pytest / pytest-pep8 / flake8.

pytest-pep8

For that, you have to use either

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

or

[pytest]
max-line-length=99

Strangely, the following does not work

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

pytest-flake8

Add

 [flake8]
 max-line-length=99


来源:https://stackoverflow.com/questions/30304409/how-to-write-a-pep8-configuration-pep8-rc-file

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!