A little background:
- PEP 8 is the Style Guide for Python Code. It contains the conventions all python programmers should follow.
- pep8.py is a (very useful) script that checks the code formating of a given python script, according to PEP 8.
- Eclipse is a great IDE. With the Pydev extension, it that can be used to develop Python
I run pep8.py manually when I'm scripting, but with bigger projects I prefer to use Eclipse. It would be really useful to integrate pep8.py in Eclipse/Pydev, so it can be run automatically in all the files in the project, and point to the lines containing the warnings. Maybe there is an obvious way to do it, but I haven't found it yet.
Question is: How to integrate pep8.py in Eclipse?
CODE ANALYSIS :
In Eclipse (PyDev), if you want to code analysis using pep8 style then
Go to:Windows -> Preferences -> PyDev -> Editor -> Code Analysis -> pep8.py tab and select Warning click Apply and OK button.
In your python code if you validate pep8 coding style it will give you warning
AUTO CODE FORMATTING :
In Eclipse (PyDev), if you want to Auto Format python code using pep8 style then
Go to:Windows -> Preferences -> PyDev -> Editor -> Code Style -> Code Formatter -> click on check-box (Use autopep8.py for console formatting?) click Apply and OK button.
If you want to increase length of line(pep8 default is 79) below Use autopep8.py you can set parameter type
--max-line-length=150
if you set max length to 150If press auto-format shortcut ( Ctrl + Shift + f ) it will automatically format your python code like pep8 style
That's it. Your Eclipse IDE is now integrated with PEP8. To run pep8.py automatically, right click on your project editor. Choose PyDev and click "code analysis". In your problems tab in your workspace, you will see warnings that points to the line that you have made a violation in the PEP8 (if you have violated).
I don't know how to integrate it for whole project, but I have used it as an external tool to analyze an individual file.
Note that the
pycodestyle
package is the official replacement for and is the newer version of thepep8
package. To install it, run:Next, in Eclipse:
pycodestyle
.Fill following fields:
Location --
${system_path:pycodestyle}
Working directory --
${container_loc}
Arguments --
"${resource_name}"
(This uses the currently active file.)Go to Common tab and confirm that the Allocate Console checkbox is checked.
A benefit of this approach is that you can use a very up-to-date version of the package, and are not limited to the old version included with PyDev. And if you are curious about setting up
pylint
in a similar manner, see this answer.You don't :) Instead you take advantage of very good integration with PyLint and configure PyLint to check all things PEP8 checks. See How to configure PyLint to check all things PEP8 checks?
As of PyDev 2.3.0,
pep8
is integrated in PyDev by default, even shipping with a default version of it.Open Window > Preferences
It must be enabled in PyDev > Editor > Code Analysis > pep8.py
Errors/Warnings should be shown as markers (as other things in the regular code analysis).
In the event a file is not analyzed, see https://stackoverflow.com/a/31001619/832230.
That does not yet appear to be fully integrated into Pydev.
As suggested in this post,
A request does exist for just that, but it seems to be still open 1 year after its creation...