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

3

26

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?

Feeder answered 18/5, 2015 at 13:23 Comment(0)
L
36

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.


Liebermann answered 17/12, 2015 at 21:8 Comment(1)
Does NOT work with pytest! What does, is pep8maxlinelength (source)Caricaria
C
3

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
Caricaria answered 8/10, 2018 at 13:39 Comment(0)
Q
2

They renamed pep8 to pycodestyle to avoid confusion.

You can create a setup.cfg file with:

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

For the error codes, you can read this documentation.

Quass answered 5/1, 2021 at 8:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.