[Qgis-developer] Changes to python/utils.py

Martin Dobias wonder.sk at gmail.com
Tue May 29 12:01:21 PDT 2012


Hi Larry

On Sat, May 26, 2012 at 2:14 AM, Larry Shaffer <larrys at dakotacarto.com> wrote:
>
> 1) Python exceptions - add lightweight debug output
>
> Currently sys.excepthook is substituted with the qgis_excepthook
> (showException() method). I propose extending showException() to
> include lightweight debug info provided by additional inquiries into
> the traceback object(s). A similar solution is here [1].
>
> [...]
>
> This provides users and developers with pertinent info on
> exception-state attribute and variable values, in addition to the
> traceback. This additional output could be directed to a second tab,
> in a new exceptions dialog, labeled 'Frames' or 'Variables'.
>
> [0] https://github.com/qgis/Quantum-GIS/blob/master/python/utils.py
> [1] http://code.activestate.com/recipes/52215/

I would really like to see that functionality - in the early times I
was happy with just a traceback - a full report with values of locals
would be surely better :-)
We could avoid adding new tabs, everything could be on one page (using
QWebView and some CSS). The table with variables for each frame could
be collapsible and inline with traceback frames - e.g. similar to how
django error pages look like [4]. Also, it would be good to have a
button to easily save the error report to allow users easily attach
error details to bug reports.

[4] http://linkaider.com/wp-content/uploads/2009/12/django-error.jpg


> 2) Module import - add deeper module tracking/reloading
>
> There has recently been work on a module [2][3] that recursively
> tracks and reloads dependent module imports in a way that I think is a
> little more robust and flexible than the current method in
> python/utils.py. I have incorporated a custom version of reloader.py
> in my Plugin Editor, with good success, for live editing/reloading of
> Python test scripts within a running QGIS instance. Plugin Installer,
> Manager, Plugin Reloader, and Plugin Editor are the only plugins (I
> know of) that utilize the reloading aspect of python/utils.py. I'm
> guessing that Plugin Reloader is used extensively in development.
>
> This correct-dependency-order recursive reload not only might allow
> plugins to be fully reloaded live, even with in-module sys.path
> adjustments, but also *retain* selected module states (see [2]
> __reload__() description). This might mean a LOT less QGIS relaunches
> during plugin development.

I am a bit afraid of the live code reloading. While I understand that
it sounds good that it would be possible to retain module state, I
think there are various cases where this would fail, e.g. if a module
fails to reload (syntax error?) or the changes from last iteration
were more significant (change of class structure?). Also, the
__reload__() callback would need to be done very carefully as it could
cause even more trouble.

I would like to keep the "hard" reload as a default since you can
trust it to do its work. The "live" reload could be eventually added,
too, as an option for the brave ones :-)

Btw. Plugins should not alter sys.path. I know that some do it, but
that's a bad idea.

Regards
Martin


More information about the Qgis-developer mailing list