Sunday, April 24, 2016

Python exceptions

When writing Python code it's import to trap errors :) And MMA does this, fairly well.

But, I just had some fun with the plugin loader. I kept getting a weird error message which didn't make a lot sense. After a bit (well, actually quite a bit!) of head scratching I finally figured it out.

In the module I have a bit of code which looked a bit like this:

        e = importlib.import_module(modName, package=None)
    except ImportError:
         error( ... report error ... )

this was meant to trap/report a problem loading the plugin module. If the module just didn't exist or was unreadable it worked fine.

But, what if the module was there and there was an error in it which caused a problem when loading? If it was something dumb like too many '(' or ')'s python reports the appropriate error as a crash. Okay, that's probably just fine. Writers of plugins should make sure that they work!

But, what if the module being loaded has a "import xxx" line? Well, since we're catching import errors, we catch it. I don't think we can set up a try/except which only works a one level.

The solution is simply to change our code to:

        e = importlib.import_module(modName, package=None)
    except ImportError, err:
        error("Plugin: Error loading module '%s'. Python is reporting '%s'. "
               "Most likely there is an Import statement in the module which is not working."% (modName, str(err)))

and now MMA reports a more useful message.

Thursday, April 14, 2016

New test version

I finally got a crappy-weather-day here. Ideal to do some needed updating to the plugin routines! Ignazio wrote a nice little module (included in the MMA module directory) with some standard functions which should make writing a plugin easier (well, more consistent). So, that along with his docs, have been added to the official tree.

I really hope some of you are taking advantage of the plugin facility. Possibilities are endless!

So you can enjoy the latest I've put a new developer version up on the website. You can get it at:

Unless we find some serious bugs, this will be the next stable release. Probably version 16.06. But who knows?

Python 2.x support

There will be one more (or two) python 2.x releases, probably this year or early 2020. I'm thinking we should remove 2.x support for MM...