@@ -330,23 +330,22 @@ def checkdep_dvipng():
330
330
return None
331
331
332
332
def 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 :
339
339
s = subprocess .Popen (
340
340
[gs_exec , '--version' ], stdout = subprocess .PIPE ,
341
341
stderr = subprocess .PIPE )
342
342
stdout , stderr = s .communicate ()
343
343
if s .returncode == 0 :
344
344
v = stdout [:- 1 ]
345
345
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
350
349
351
350
def checkdep_tex ():
352
351
try :
@@ -523,7 +522,11 @@ def _get_xdg_config_dir():
523
522
base directory spec
524
523
<http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html>`_.
525
524
"""
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' ))
527
530
528
531
529
532
def _get_xdg_cache_dir ():
@@ -532,7 +535,11 @@ def _get_xdg_cache_dir():
532
535
base directory spec
533
536
<http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html>`_.
534
537
"""
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' ))
536
543
537
544
538
545
def _get_config_or_cache_dir (xdg_base ):
@@ -548,22 +555,27 @@ def _get_config_or_cache_dir(xdg_base):
548
555
return _create_tmp_config_dir ()
549
556
return configdir
550
557
558
+ p = None
551
559
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
565
577
566
- return p
578
+ return _create_tmp_config_dir ()
567
579
568
580
569
581
def _get_configdir ():
@@ -719,9 +731,11 @@ def matplotlib_fname():
719
731
if configdir is not None :
720
732
fname = os .path .join (configdir , 'matplotlibrc' )
721
733
if os .path .exists (fname ):
734
+ home = get_home ()
722
735
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' ))):
725
739
warnings .warn (
726
740
"Found matplotlib configuration in ~/.matplotlib/. "
727
741
"To conform with the XDG base directory standard, "
@@ -730,6 +744,8 @@ def matplotlib_fname():
730
744
"Please move your configuration there to ensure that "
731
745
"matplotlib will continue to find it in the future." %
732
746
_get_xdg_config_dir ())
747
+ return os .path .join (
748
+ home , '.matplotlib' , 'matplotlibrc' )
733
749
return fname
734
750
735
751
path = get_data_path () # guaranteed to exist or raise
0 commit comments