Monday, August 11, 2008

Pylint On WingIDE Check on Save!

Now lets face it, for a data typeless language like python, its easy to get errors that other languages IDE would have picked up easily. For example, if you were to point "ooo = hellu()" and hellu() is actually a typo, it should have been "hello()". You wont get any error on the IDE until you run it.

This becomes pretty irritating when u have a number of these erorrs occuring when you are running your applications and you wished such flimsy bugs would have been picked by the IDE before you ever ran it.

Solution : Use Pylint.
Install it and goto "tools"->pylint and you will see a window on the right handside with "pylint" as the tab caption. (pls refer to other documentation on where to get and install pylint)

And what you need now is to have Pylint autocheck everytime u save a module so that all modules gets pre-checked and those irritating typos i mentioned earlier and other bugs will get caught.

Here is what you do, open up "editor-extensions.py" found in ur WingIDE installed directory under "scripts" (make a backup of this file first to somewhere else). Add the following lines at the end :-


def _connect_to_savepoint(doc):


def _on_savepoint(val):

if val == 0 :
return

# Get editor and do action
ed = wingapi.gApplication.GetActiveDocument()
if ed == None :
return

wingapi.gApplication.ExecuteCommand('pylint-execute')

connect_id = doc.Connect('save-point', _on_savepoint)


def _savepointinit():
wingapi.gApplication.Connect('document-open', _connect_to_savepoint)
for doc in wingapi.gApplication.GetOpenDocuments():
_connect_to_savepoint(doc)

_savepointinit()



And there you have it! Pylint total integration. Notice that if you open new modules and save it sometimes u get the "tried to execute an unavailable command .internal.gui.save". Just ignore this, the autosave in Pylint makes the IDE notice that you dont need to save the file again.

No comments:

Post a Comment