Tuesday, January 28, 2014

New PyDev release: improved indexing, Kivy support on LiClipse, etc.

PyDev 3.3.3 is now released.

For this release, there are lots of enhancements in many areas (full details on http://pydev.org).

My favorite one is that PyDev will now index completions from compiled modules (i.e.: .pyd files or entries in the 'forced builtins' -- http://pydev.org/manual_101_interpreter.html has more details on what are forced builtins). This was a long due request but it required the many other incremental changes from recent releases to be feasible.

With that, the context-insensitive code completion (the one that'll automatically add an import for the token) will work for libraries such as PyQt, itertools, etc.

Another which is really nice is that in the debugger, changing a local variable works properly (until now, this did work sometimes, but usually it didn't, as it had shortcomings depending on what variable was changed and how it was put in the scope and whether it was the top frame). Now this works even when assigning a local in the Debug Console!

Also in the debugger, now it's possible to mark some functions that you want to ignore in the debugger with a comment: #@DontTrace and when stepping in the debugger will ignore those: this is a huge time saver when debugging to ignore paths which are just scaffolding (and many times get in the way during a debug session).

As for LiClipse, the Kivy language is now supported -- it has syntax highlighting, code-completion, outline and many other goodies you'd expect. Besides this, in the latest release (0.9.7) LiClipse users can benefit from mark occurrences in the created editors and the theming now applies to EGit views too (more details on http://brainwy.github.io/liclipse).

Now, this is just a brief and incomplete summary of the changes. Personally, I think that PyDev improved on so many things in this release that it's a must have update if you're a PyDev/LiClipse user (especially performance-wise) -- I almost thought about making it a version 4.0 coming from 3.2, but I just couldn't skip doing a 3.3.3 version :)

Wednesday, January 08, 2014

Profiling a method on Python

This week I needed to do a profile session and usually on Python I just use the profile module and dump the output stats (of cProfile) in textual mode (which is usually enough to find out about the problem).

Now, this week I had to do some profiling which demanded a bit more, so, researching a bit, it seems that graphviz (http://www.graphviz.org/) can be used to plot the results of the profile session output with the help of gprof2dot (http://gprof2dot.jrfonseca.googlecode.com/git/gprof2dot.py).

So, using the code below (gist from https://gist.github.com/fabioz/8314370), it's possible to profile a function and have a graphical (.svg) output with the results of the profile (besides the usual text output, which I usually save temporarily during a profile session to compare the results from subsequent optimizations).

Hopefully the docstring explains how to use it properly (as well as its dependencies):




Note that it relies on having a .svg viewer installed (I had Inkscape: http://www.inkscape.org/ installed, so, I'm just using it, but there may be better .svg viewers around).

Happy profiling!