@@ -519,35 +519,38 @@ def _get_xdg_cache_dir():
519
519
def _get_config_or_cache_dir (xdg_base_getter ):
520
520
configdir = os .environ .get ('MPLCONFIGDIR' )
521
521
if configdir :
522
- configdir = Path (configdir ). resolve ()
522
+ configdir = Path (configdir )
523
523
elif sys .platform .startswith (('linux' , 'freebsd' )):
524
524
# Only call _xdg_base_getter here so that MPLCONFIGDIR is tried first,
525
525
# as _xdg_base_getter can throw.
526
526
configdir = Path (xdg_base_getter (), "matplotlib" )
527
527
else :
528
528
configdir = Path .home () / ".matplotlib"
529
+ # Resolve the path to handle potential issues with inaccessible symlinks.
530
+ configdir = configdir .resolve ()
529
531
try :
530
532
configdir .mkdir (parents = True , exist_ok = True )
531
- except OSError :
532
- pass
533
+ except OSError as exc :
534
+ _log . warning ( "mkdir -p failed for path %s: %s" , configdir , exc )
533
535
else :
534
536
if os .access (str (configdir ), os .W_OK ) and configdir .is_dir ():
535
537
return str (configdir )
538
+ _log .warning ("%s is not a writable directory" , configdir )
536
539
# If the config or cache directory cannot be created or is not a writable
537
540
# directory, create a temporary one.
538
541
try :
539
542
tmpdir = tempfile .mkdtemp (prefix = "matplotlib-" )
540
543
except OSError as exc :
541
544
raise OSError (
542
- f"Matplotlib requires access to a writable cache directory, but the "
543
- f"default path ({ configdir } ) is not a writable directory , and a temporary "
545
+ f"Matplotlib requires access to a writable cache directory, but there "
546
+ f"was an issue with the default path ({ configdir } ), and a temporary "
544
547
f"directory could not be created; set the MPLCONFIGDIR environment "
545
548
f"variable to a writable directory" ) from exc
546
549
os .environ ["MPLCONFIGDIR" ] = tmpdir
547
550
atexit .register (shutil .rmtree , tmpdir )
548
551
_log .warning (
549
- "Matplotlib created a temporary cache directory at %s because the default path "
550
- "(%s) is not a writable directory ; it is highly recommended to set the "
552
+ "Matplotlib created a temporary cache directory at %s because there was "
553
+ "an issue with the default path (%s) ; it is highly recommended to set the "
551
554
"MPLCONFIGDIR environment variable to a writable directory, in particular to "
552
555
"speed up the import of Matplotlib and to better support multiprocessing." ,
553
556
tmpdir , configdir )
0 commit comments