Getting started with pylint

‘‘How to get started with pylint and melange in eclipse’’

Prerequisites

Melange must be checked out succesfully and set up correctly, read Melange [GettingStarted] guide for more. Also you will need to download pylint and its dependencies, logilab-astng and logilab-common.

Install

To get pylint working correctly you must first install its dependencies, in order to install its dependencies you may need to have administrator privileges depending on who installed python in your computer(you or the administrator) to avoid confusion this guide will proceed as if you where the administrator.

  • Extract both pylint and its dependencies.
  • Execute python setup.py install from logilab-common folder.
  • Execute python setup.py install from logilab-astng folder.
  • Execute python setup.py install from pylint folder.

Putting pylint in your system path

Now if you want to run pylint from your prefered shell you may want to put the executable in your system path. To do this you just put Python25Path/Scripts in your system path:

If you are using ‘‘windows’’ you will place Python25Path\Scripts under the PATH variable here you can find a guide on how to set system variables on windows xp and go here if you are using vista.

If you are using ‘‘linux’’ you will set {need to know where is the scripts directory!}

Now pylint should be fully installed.

Making pylint work with pydev

Pydev is an eclipse plugin to work with python projects, the rest of this guide focus on making pylint work with pydev and Melange.

Now to get pylint working with pydev you need to install pydev then you should configure pydev to run pylint every time pydev builds the workspace, here is a guide on that, you may need to know that the lint.py file should be placed on /usr/local/lib/pythonX.Y/site-packages/pylint on linux and PythonInstallDir\Lib\site-packages\pylint on windows.

?-X.Y stands for the python version that you are running.

Making pylint ‘see’ app engine and its dependencies

Now that pylint is installed in your system and configured in eclipse the first thing you need to do is make pydev see app engine dependencies here is a good youtube video on that. Now that pydev is finding all app engine references in Melange, pylint may not be seeing app engine dependencies correctly. In order to solve that possible problem you have to install app engine dependencies in your sites_package directory the same way we did with pylint and its dependencies.

  • Go to MelangeCheckoutDir\thirdparty\google_appengine\lib\
  • Run python yaml\setup.py install
  • Run python webob\setup.py install (needs setup_tools to install)
  • Run python django\setup.py install
  • Run python antlr3\setup.py install

Pylint usage

As this may be enough for most projects but Melange has special needs. Many aspects both in melange and app engine can't be identified by pylint so an instruction in the code can be marked as incorrect while is fully correct. Example:

org = Organization.get_by_key_name('google/gsoc2009/%d' % i)
key=org.key()

In the previous section of code Organization is a model. The second line is marked as incorrect because pylint says the method Model.get_by_key_name() returns a list. If you look at the Model implementation in app engine folder you will see that the method get_by_key_name() returns a result of Model.get() that in fact can returns, sometimes, a list.

In order to avoid these problems the programmer should feel encouraged to place special comments in the code to make pylint ignore these lines of code, if that section of code is proved correct.

Example:

org = Organization.get_by_key_name('google/gsoc2009/%d' % i)
# pylint: disable-msg=E1103
key=org.key()
# pylint: enable-msg=E1103

In the previous section of code pylint would normally say that there is an error in the third line. However since we placed a special comment telling pylint to ignore that error checking in that line, no warning is issued.

By placing a comment like this before the wronged line:

# pylint: disable-msg=(Error Code)

The error with the declared error code is ignored for the rest of this module until it sees:

# pylint: enable-msg=(Error Code)

That re-enables that error checking trough the rest of the code.

There are some cases where pylint error skipping shouldn't be re-enabled like:

# pylint: disable-msg=W0311

This comment disable pylint checking for 4 spaces identing, as you can se here melange enforces the use of 2 spaces for identing so leaving this checking disabled can be intentional.

The pylint rc-file

As a final note, Melange has already included in MelangeCheckoutDir\scripts\pylint\ a file named pylintrc that is a configurations file for pylint it has almost all the problems that you might have with pylint on Melange solved. To make eclipse pass it to pylint on every build add the following line to the pydev>pylint>Pylint arguments under the preferences view in eclipse:

--rcfile=Absolutepath_to_MelangeDir/scripts/pylint/pylintrc