@@ -531,7 +531,11 @@ def _get_xdg_config_dir():
531531 base directory spec
532532 <http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html>`_.
533533 """
534- return os .environ .get ('XDG_CONFIG_HOME' , os .path .join (get_home (), '.config' ))
534+ home = get_home ()
535+ if home is None :
536+ return None
537+ else :
538+ return os .environ .get ('XDG_CONFIG_HOME' , os .path .join (home , '.config' ))
535539
536540
537541def _get_xdg_cache_dir ():
@@ -540,7 +544,11 @@ def _get_xdg_cache_dir():
540544 base directory spec
541545 <http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html>`_.
542546 """
543- return os .environ .get ('XDG_CACHE_HOME' , os .path .join (get_home (), '.cache' ))
547+ home = get_home ()
548+ if home is None :
549+ return None
550+ else :
551+ return os .environ .get ('XDG_CACHE_HOME' , os .path .join (home , '.cache' ))
544552
545553
546554def _get_config_or_cache_dir (xdg_base ):
@@ -556,22 +564,28 @@ def _get_config_or_cache_dir(xdg_base):
556564 return _create_tmp_config_dir ()
557565 return configdir
558566
567+ p = None
559568 h = get_home ()
560- p = os .path .join (h , '.matplotlib' )
561- if (sys .platform .startswith ('linux' ) and
562- not os .path .exists (p )):
563- p = os .path .join (xdg_base , 'matplotlib' )
564-
565- if os .path .exists (p ):
566- if not _is_writable_dir (p ):
567- return _create_tmp_config_dir ()
568- else :
569- try :
570- mkdirs (p )
571- except OSError :
572- return _create_tmp_config_dir ()
569+ if h is not None :
570+ p = os .path .join (h , '.matplotlib' )
571+ if (sys .platform .startswith ('linux' ) and
572+ not os .path .exists (p ) and
573+ xdg_base is not None ):
574+ p = os .path .join (xdg_base , 'matplotlib' )
575+
576+ if p is not None :
577+ if os .path .exists (p ):
578+ if _is_writable_dir (p ):
579+ return p
580+ else :
581+ try :
582+ mkdirs (p )
583+ except OSError :
584+ pass
585+ else :
586+ return p
573587
574- return p
588+ return _create_tmp_config_dir ()
575589
576590
577591def _get_configdir ():
@@ -727,9 +741,11 @@ def matplotlib_fname():
727741 if configdir is not None :
728742 fname = os .path .join (configdir , 'matplotlibrc' )
729743 if os .path .exists (fname ):
744+ home = get_home ()
730745 if (sys .platform .startswith ('linux' ) and
746+ home is not None and
731747 fname == os .path .join (
732- get_home () , '.matplotlib' , 'matplotlibrc' )):
748+ home , '.matplotlib' , 'matplotlibrc' )):
733749 warnings .warn (
734750 "Found matplotlib configuration in ~/.matplotlib/. "
735751 "To conform with the XDG base directory standard, "
0 commit comments