Friday, February 8, 2013

configuring PEP8.py support in PyCharm 2.7

UPDATE
Jetbrains developer Dmitry Jemerov contacted me on twitter with a much quicker way to do this.

Jetbrains released their latest version of the PyCharm python IDE, and one of the great new features is integration with pep8.py. For those who don't know what pep8 is, pep stands for Python Enhancement Proposal. The PSF(Python Software Foundation) keeps a list of these proposals, and each one gets a number. pep8 is a style guide for python that many projects follow, and to make it easier for programmers to check that their code follows these style guides, pep8.py was created, a tool that automatically checks for pep8 compliance.

With this tool integrated into PyCharm, the IDE will show you where you're violating pep8 rules, but here's my problem. pep8 says you should use spaces for indentation, while I strongly prefer tabs, so every line showed an error for me. You can configure pep8 to ignore certain errors, but it wasn't immediately clear to me how. I found out after a bit of digging around, but I want to save you some time. So with no further adue, here's how to do it.

  1. In pycharm, click the settings icon, or go to the settings via the menu bar.
  2. In the project settings section, click 'inspections'
  3. In the list that appears, click 'python'.
  4. Under python, scroll down and click PEP8.
  5. Now, underneath the description, you'll se an 'ignore errors' section. Click the + at the bottom.
  6. Now, go here. This is a page of the pep8.py documentation, listing all possible errors and warnings.
  7. Find an error you want to ignore, and copy the error code at the left.
  8. Paste this error code into the field you just added in the settings window.<:li>
  9. Add all the errors you want to ignore and click apply.

The changes will immediately take effect, without a need to restart.