Saturday, June 21, 2008

Configuring tvtk / forced builtins

Recently, there was a report on problems while configuring tvtk (it's a pythonic API over vtk).

Having the import:

from enthought.tvtk.api import tvtk

did not bring any completions while later using 'tvtk.' on that module.

This happens because the code in tvtk does some black-magic to load the classes in that module... there's a module called enthought.tvtk.tvtk that has a class tvtk that's actually what's imported in "from enthought.tvtk.api import tvtk", so, the solution is adding "enthought.tvtk.tvtk.tvtk" to the "forced builtins", so that pydev can understand that it should be dynamically analyzed.

More info on the "forced builtins" can be found at: and yes: finding out what should be dynamically analyzed and what shouldn't can be very tricky some times...

Pydev 1.3.18

The major feature on this release was the (organize imports feature, along with some bug-fixes...

There's even one bug-fix I think it's worth talking about:

Pydev was using Runtime.exec(cmd) to execute the shell/gather interpreter info, and that wasn't very portable among platforms, resulting in problems when paths contained spaces. Now, in 1.3.18, the Runtime.exec(cmd[]) (using an array to pass parameters) is being used, and that should fix the 'spaces on install' problem -- actually, there was a partial fix on 1.3.17 for that, but some places still used the wrong API... now, on 1.3.18, all places should be using the new API.

Sunday, June 15, 2008

Organizing imports

One of the features I can't live without in Pydev Extensions is the auto-import. Basically, when you want to get a class/method into the namespace, just start writing it, request a completion and the class will be completed and an import for it will be added at the top-level part of the file (it's similar to what JDT does).

So, after using this feature lots of times, one thing that started happening is that some modules would end with imports such as:

from mod1 import Class1
from mod1 import Class2
from mod1 import Class3

Now, on version 1.3.18, the auto-import will group imports when requested, so, after making those requests it'd become:

from mod1 import Class1, Class2, Class3

But that won't group existing imports... For that, the organize imports action was improved -- until now, Ctrl+Shift+O would only sort the imports alphabetically, but from now on it'll also group them, and if Pydev Extensions is available, for each undefined token found in the code analysis, an option to add an import to one of the available definitions of the token will be presented -- which is especially useful when doing refactorings and cutting/copying code from one place to another.