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