Thursday, June 23, 2011

Installing Pylint for Python 2.5 on Mac

In a previous post I discussed how to set up Google App Engine (Python) development environment on Mac OS X 10.6. I'm liberally mining some of my own notes on setting up Google App Engine on Ubuntu 10.10.

In my previous Ubuntu environment I had a neat Ant script for building, testing and uploading my Google App Engine applications such as My Web Brain. One of tests the script performed was Python code style checks using Pylint, which I have also mentioned before in the context of Ubuntu. I've set this up again on my Mac, so I thought I thought I would post my notes here.

In this post I talk about:

  • Installing Setup Tools for Python 2.5,
  • Installing PyLint using SetupTools, and
  • Configuring Aptana/Pydev to use PyLint
Lets go!

A couple of pre-requisites first: You need to have enabled the root user to be able to Sudo and I'm assuming you have already installed Python 2.5 (see my previous post for more information on that)

Installing SetupTools

I still prefer to install Pylint via SetupTools. SetupTools makes the easy_install command available from the shell to automatically install python eggs and sort out their dependencies. You might already have SetupTools on your system, but do you have the Python 2.5 version? I assume it is important (it does after all need to install packages into the correct site-packages folder). To install SetupTools, first download the egg file:

http://pypi.python.org/packages/2.5/s/setuptools/setuptools-0.6c11-py2.5.egg

Open a terminal session and cd into the folder you saved it into. Type the following into the commandline:

$ sudo sh setuptools-0.6c11-py2.5.egg

This will install setup tools. When you run easy_install, make sure to use the command easy_install-2.5 to make sure you are addressing the correct Python installation on your system.

Installing PyLint 

Type the following into your terminal shell:

$ sudo easy_install-2.5 pylint

This will install PyLint and all of its dependencies. You can now run PyLint from the command line (or from an Ant Task).

Using PyLint in Aptana

Aptana (now incorporating PyDev - again see my previous post) can integrate with PyLint to give you feedback on code style as you work and make changes to your source files. To configure Aptana to do this, open Preferences -> Pydev -> PyLint, check the the Use PyLint option and locate your Pylint executable. Despite the hint to look for a file named lint.py, I've never found such a file.

Instead, find the pylint binary. If you installed PyLint as per the above the following path should be where it is at:

/Library/Frameworks/Python.framework/Versions/2.5/bin/pylint

Click OK, open a python file and make some changes. Warnings and errors from PyLint should start appearing in the Problems view (Window -> Show View -> Problems if you can't see it). You can also specify a preferences file in the preferences page for PyLint to pass in any global settings (to ignore certain style rules, for example).

There you go. PyLint is installed and ready to use from the command line, an Ant Task or in Aptana. Let me know in the comments if you can suggest a better approach, have a question or any sort of general comment.

1 comment: