Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to integrate pep8.py in Eclipse?

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?

like image 637
David Arcos Avatar asked Dec 30 '08 10:12

David Arcos


2 Answers

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.

like image 199
Fabio Zadrozny Avatar answered Oct 15 '22 00:10

Fabio Zadrozny


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 the pep8 package. To install it, run:

$ sudo pip install --upgrade pycodestyle 

Next, in Eclipse:

  1. Select Run-External Tools-External Tools Configurations...
  2. Select Program root node.
  3. Press New launch configuration button.
  4. Enter Name for your launch configuration. I use pycodestyle.
  5. 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.

like image 37
Dmitry Kochkin Avatar answered Oct 15 '22 01:10

Dmitry Kochkin