ActiveBlog

Writing PEP8-aware Python Code in Komodo
by Sridhar Ratnakumar

Sridhar Ratnakumar, September 17, 2010

PEP 8 (the document) is the official coding style guide for Python programmers. pep8 (the utility) is a tool to check for style deviations in your Python source code. Here is how you can quickly integrate pep8 checking for your code in Komodo.

Komodo Run Command... Dialog

 
  1. Install ActivePython (2.6 or 2.7)
  2. Open the command prompt and type pypm install pep8 -- this installs the pep8 tool.
  3. In Komodo, open one of your Python source file
  4. Tools -> Run Command...
    1. Enter pep8 "%F" [1] in the command entry
    2. Click the "more" button
    3. Check "Parse output with" and select the sample regexp entry in the combo box - "(?P<file>.+?):(?P<line>\d+):(?P<content>.*)"
    4. Check "Show parsed output as a list"
    5. Check "Add to Toolbox"
  5. Click the 'Run' button; you should see something like this in the bottom pane

Command Output

Komodo automatically parses the output of pep8 and displays it as a list of clickable entries. When you double-click on an item, Komodo takes you to the appropriate line in the source.

In addition, as you may have already noticed, due to selecting "Add to Toolbox" in step 5 above, Komodo immediately added a new tool to your toolbox. This makes it much easier to repeatedly invoke the pep8 tool without having to repeat the above steps. Open a different Python source file and simply double-click on the newly created tool to run pep8 on the new file again.

Saved Command in the Toolbox

If you use pep8 more often, then it is helpful to add a keybinding to it. To do this, right-click on the command in the Toolbox, select Properties and then go to the Key Binding tab. Here you can add your new keybinding (I used Cmd+Shift+P).

[1]If pep8 doesn't run, try giving the full path to it, which you can find by running pypm files pep8.

Subscribe to ActiveState Blogs by Email

Share this post:

Category: python
About the Author: RSS

Sridhar Ratnakumar is a senior Python developer at ActiveState where he works tirelessly to ensure that ActivePython is the world's highest quality Python distribution. He's been developing on Python since 2003 and is the author of various Python modules, including pyrtm and applib. He earned his software development stripes at Amazon and Microsoft.

Comments

3 comments for Writing PEP8-aware Python Code in Komodo
Permalink

Very cool step-by-step process to get this up and running. Thanks for putting it together. It took under 5 minutes to get everything in place, including the download. Alternatively one can use "easy_install pep8" to download and install the python module tool.

Permalink

Awesome tip! to note, pep8 is available from pypi as well so you can easy_install or if your on ubuntu, you can apt-get install pep8

Thanks for this

Permalink

Thanks, I had something similar using Kohana and the CodeCoverage package but wanted an equivalent feature in python.