@@ -330,23 +330,22 @@ def checkdep_dvipng():
330330 return None
331331
332332def checkdep_ghostscript ():
333- try :
334- if sys . platform == 'win32' :
335- gs_execs = [ 'gswin32c' , 'gswin64c' , 'gs' ]
336- else :
337- gs_execs = [ 'gs' ]
338- for gs_exec in gs_execs :
333+ if sys . platform == 'win32' :
334+ gs_execs = [ 'gswin32c' , 'gswin64c' , 'gs' ]
335+ else :
336+ gs_execs = [ 'gs' ]
337+ for gs_exec in gs_execs :
338+ try :
339339 s = subprocess .Popen (
340340 [gs_exec , '--version' ], stdout = subprocess .PIPE ,
341341 stderr = subprocess .PIPE )
342342 stdout , stderr = s .communicate ()
343343 if s .returncode == 0 :
344344 v = stdout [:- 1 ]
345345 return gs_exec , v
346-
347- return None , None
348- except (IndexError , ValueError , OSError ):
349- return None , None
346+ except (IndexError , ValueError , OSError ):
347+ pass
348+ return None , None
350349
351350def checkdep_tex ():
352351 try :
@@ -523,7 +522,11 @@ def _get_xdg_config_dir():
523522 base directory spec
524523 <http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html>`_.
525524 """
526- return os .environ .get ('XDG_CONFIG_HOME' , os .path .join (get_home (), '.config' ))
525+ home = get_home ()
526+ if home is None :
527+ return None
528+ else :
529+ return os .environ .get ('XDG_CONFIG_HOME' , os .path .join (home , '.config' ))
527530
528531
529532def _get_xdg_cache_dir ():
@@ -532,7 +535,11 @@ def _get_xdg_cache_dir():
532535 base directory spec
533536 <http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html>`_.
534537 """
535- return os .environ .get ('XDG_CACHE_HOME' , os .path .join (get_home (), '.cache' ))
538+ home = get_home ()
539+ if home is None :
540+ return None
541+ else :
542+ return os .environ .get ('XDG_CACHE_HOME' , os .path .join (home , '.cache' ))
536543
537544
538545def _get_config_or_cache_dir (xdg_base ):
@@ -548,22 +555,27 @@ def _get_config_or_cache_dir(xdg_base):
548555 return _create_tmp_config_dir ()
549556 return configdir
550557
558+ p = None
551559 h = get_home ()
552- p = os .path .join (h , '.matplotlib' )
553- if (sys .platform .startswith ('linux' ) and
554- not os .path .exists (p )):
555- p = os .path .join (xdg_base , 'matplotlib' )
556-
557- if os .path .exists (p ):
558- if not _is_writable_dir (p ):
559- return _create_tmp_config_dir ()
560- else :
561- try :
562- mkdirs (p )
563- except OSError :
564- return _create_tmp_config_dir ()
560+ if h is not None :
561+ p = os .path .join (h , '.matplotlib' )
562+ if (sys .platform .startswith ('linux' ) and
563+ xdg_base is not None ):
564+ p = os .path .join (xdg_base , 'matplotlib' )
565+
566+ if p is not None :
567+ if os .path .exists (p ):
568+ if _is_writable_dir (p ):
569+ return p
570+ else :
571+ try :
572+ mkdirs (p )
573+ except OSError :
574+ pass
575+ else :
576+ return p
565577
566- return p
578+ return _create_tmp_config_dir ()
567579
568580
569581def _get_configdir ():
@@ -719,9 +731,11 @@ def matplotlib_fname():
719731 if configdir is not None :
720732 fname = os .path .join (configdir , 'matplotlibrc' )
721733 if os .path .exists (fname ):
734+ home = get_home ()
722735 if (sys .platform .startswith ('linux' ) and
723- fname == os .path .join (
724- get_home (), '.matplotlib' , 'matplotlibrc' )):
736+ home is not None and
737+ os .path .exists (os .path .join (
738+ home , '.matplotlib' , 'matplotlibrc' ))):
725739 warnings .warn (
726740 "Found matplotlib configuration in ~/.matplotlib/. "
727741 "To conform with the XDG base directory standard, "
@@ -730,6 +744,8 @@ def matplotlib_fname():
730744 "Please move your configuration there to ensure that "
731745 "matplotlib will continue to find it in the future." %
732746 _get_xdg_config_dir ())
747+ return os .path .join (
748+ home , '.matplotlib' , 'matplotlibrc' )
733749 return fname
734750
735751 path = get_data_path () # guaranteed to exist or raise
0 commit comments