matplotlib: two issues with MPLCONFIGDIR

The Sage developers have found two issues with MPLCONFIGDIR:

- First, when upgrading from version 0.99.3 to 1.0.0, the contents of
that directory seem to cause compatibility problems. That is, once
you upgrade to a version of Sage using 1.0.0, it overwrites whatever
was in that directory, and then you get errors when using an older
version of Sage which still uses 0.99.3. See
<> for an
example of the sort of error which arises, and see
<> for our fix: in Sage,
we set MPLCONFIGDIR to different directories based on the version of

- Second, the following code in matplotlib/ can cause a
race condition when creating MPLCONFIGDIR:

    if not os.path.exists(texcache):

In particular, when running doctests for Sage, if MPLCONFIGDIR doesn't
exist, two different doctests can try to create it at the same time,
causing a problem. (I've also heard people suggest that these sort of
race conditions can be security issues, but I don't know about the
validity of this.) See
<> for our fix: we
replace those lines by

    except OSError, e:
        assert e.errno==errno.EEXIST, 'Cannot create %s.' % texcache

(and also add "import errno" at the beginning of the file).

I'd be happy to hear any comments you might have about these.


John Palmieri