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
<http://trac.sagemath.org/sage_trac/ticket/9221#comment:82> for an
example of the sort of error which arises, and see
<http://trac.sagemath.org/sage_trac/ticket/6235> for our fix: in Sage,
we set MPLCONFIGDIR to different directories based on the version of
matplotlib.

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

    if not os.path.exists(texcache):
        os.mkdir(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
<http://trac.sagemath.org/sage_trac/ticket/10159> for our fix: we
replace those lines by

    try:
        os.mkdir(texcache)
    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