@@ -531,7 +531,11 @@ def _get_xdg_config_dir():
531
531
base directory spec
532
532
<http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html>`_.
533
533
"""
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' ))
535
539
536
540
537
541
def _get_xdg_cache_dir ():
@@ -540,7 +544,11 @@ def _get_xdg_cache_dir():
540
544
base directory spec
541
545
<http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html>`_.
542
546
"""
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' ))
544
552
545
553
546
554
def _get_config_or_cache_dir (xdg_base ):
@@ -556,22 +564,28 @@ def _get_config_or_cache_dir(xdg_base):
556
564
return _create_tmp_config_dir ()
557
565
return configdir
558
566
567
+ p = None
559
568
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
573
587
574
- return p
588
+ return _create_tmp_config_dir ()
575
589
576
590
577
591
def _get_configdir ():
@@ -727,9 +741,11 @@ def matplotlib_fname():
727
741
if configdir is not None :
728
742
fname = os .path .join (configdir , 'matplotlibrc' )
729
743
if os .path .exists (fname ):
744
+ home = get_home ()
730
745
if (sys .platform .startswith ('linux' ) and
746
+ home is not None and
731
747
fname == os .path .join (
732
- get_home () , '.matplotlib' , 'matplotlibrc' )):
748
+ home , '.matplotlib' , 'matplotlibrc' )):
733
749
warnings .warn (
734
750
"Found matplotlib configuration in ~/.matplotlib/. "
735
751
"To conform with the XDG base directory standard, "
0 commit comments