[Isaac] Matplotlib problem under Windows: %HOME% expands to %USERPROFILE%

THE HACK for Windows users with the problematic install and

    > behavior: change HOME to USERPROFILE in font_manager.py.

Hi Alan,

Thanks for the bug report and the pointer to the solution I added the
following code to matplotlib.__init__.py above the get_data_path
function

def get_home():
    """
    return the users HOME dir across platforms or None.
    
    On win32, if either HOME is not set or HOME is set but doesn't
    exist, the value of USERPROFILE will be used instead.
    """

    if os.environ.has_key('HOME'):
        path = os.environ['HOME']
        if os.path.exists(path): return path

    if sys.platform=='win32' and os.environ.has_key('USERPROFILE'):
        path = os.environ['USERPROFILE']
        if os.path.exists(path): return path

    return None

And then use this everywhere in the code that wants HOME.
Fortunately, that is only two places, once in matplotlib_fname and
once in the font_manager.

In font_manager, if you import it

from matplotlib import rcParams, get_data_path, get_home

and use it

        ttfpath = get_home()
        if ttfpath is None: ttfpath = get_data_path()
        ttfcache = os.path.join(ttfpath, '.ttffont.cache')

it should fix the bug.

Would you mind testing it for me? I tried it on a linux and winxp
platform and it worked. But I never had problems before on those two
platforms so it would be helpful to try yours as well.

Thanks!
JDH

Seems to work fine.
I also changed font_manager.py the same way:
        Change
                afmpath = os.environ.get('USERPROFILE', get_data_path())
        to
                afmpath = get_home()
                if afmpath is None: afmpath = get_data_path()

Sidenote:
recall that because of this problem, during installation
I ended up with a directory named literally
        Python23\%USERPROFILE
literally. Until I removed this, get_home did not work
quite right (because the first existence test was unexpectedly true!)
So you'll want to make sure this installation problem is
also gone.

Cheers,
Alan Isaac

···

On Wed, 18 Aug 2004, John Hunter apparently wrote:

Would you mind testing it for me? I tried it on a linux and winxp
platform and it worked. But I never had problems before on those two
platforms so it would be helpful to try yours as well.