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