@@ -532,7 +532,11 @@ def _get_xdg_config_dir():
532532 base directory spec
533533 <http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html>`_.
534534 """
535- return os .environ .get ('XDG_CONFIG_HOME' , os .path .join (get_home (), '.config' ))
535+ home = get_home ()
536+ if home is None :
537+ return None
538+ else :
539+ return os .environ .get ('XDG_CONFIG_HOME' , os .path .join (home , '.config' ))
536540
537541
538542def _get_xdg_cache_dir ():
@@ -541,7 +545,11 @@ def _get_xdg_cache_dir():
541545 base directory spec
542546 <http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html>`_.
543547 """
544- return os .environ .get ('XDG_CACHE_HOME' , os .path .join (get_home (), '.cache' ))
548+ home = get_home ()
549+ if home is None :
550+ return None
551+ else :
552+ return os .environ .get ('XDG_CACHE_HOME' , os .path .join (home , '.cache' ))
545553
546554
547555def _get_config_or_cache_dir (xdg_base ):
@@ -557,22 +565,28 @@ def _get_config_or_cache_dir(xdg_base):
557565 return _create_tmp_config_dir ()
558566 return configdir
559567
568+ p = None
560569 h = get_home ()
561- p = os .path .join (h , '.matplotlib' )
562- if (sys .platform .startswith ('linux' ) and
563- not os .path .exists (p )):
564- p = os .path .join (xdg_base , 'matplotlib' )
565-
566- if os .path .exists (p ):
567- if not _is_writable_dir (p ):
568- return _create_tmp_config_dir ()
569- else :
570- try :
571- mkdirs (p )
572- except OSError :
573- return _create_tmp_config_dir ()
570+ if h is not None :
571+ p = os .path .join (h , '.matplotlib' )
572+ if (sys .platform .startswith ('linux' ) and
573+ not os .path .exists (p ) and
574+ xdg_base is not None ):
575+ p = os .path .join (xdg_base , 'matplotlib' )
576+
577+ if p is not None :
578+ if os .path .exists (p ):
579+ if _is_writable_dir (p ):
580+ return p
581+ else :
582+ try :
583+ mkdirs (p )
584+ except OSError :
585+ pass
586+ else :
587+ return p
574588
575- return p
589+ return _create_tmp_config_dir ()
576590
577591
578592def _get_configdir ():
@@ -728,9 +742,11 @@ def matplotlib_fname():
728742 if configdir is not None :
729743 fname = os .path .join (configdir , 'matplotlibrc' )
730744 if os .path .exists (fname ):
745+ home = get_home ()
731746 if (sys .platform .startswith ('linux' ) and
747+ home is not None and
732748 fname == os .path .join (
733- get_home () , '.matplotlib' , 'matplotlibrc' )):
749+ home , '.matplotlib' , 'matplotlibrc' )):
734750 warnings .warn (
735751 "Found matplotlib configuration in ~/.matplotlib/. "
736752 "To conform with the XDG base directory standard, "
0 commit comments