Writing PEP8-aware Python Code in Komodo

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.

  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.

Recent Posts

Scroll to Top