Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1b08207

Browse files
authored
Merge pull request #28818 from hintron/28817-v1
Resolve configdir so that it's not a symlink when is_dir() is called
2 parents 56153b9 + 8837d9a commit 1b08207

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

lib/matplotlib/__init__.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -519,35 +519,38 @@ def _get_xdg_cache_dir():
519519
def _get_config_or_cache_dir(xdg_base_getter):
520520
configdir = os.environ.get('MPLCONFIGDIR')
521521
if configdir:
522-
configdir = Path(configdir).resolve()
522+
configdir = Path(configdir)
523523
elif sys.platform.startswith(('linux', 'freebsd')):
524524
# Only call _xdg_base_getter here so that MPLCONFIGDIR is tried first,
525525
# as _xdg_base_getter can throw.
526526
configdir = Path(xdg_base_getter(), "matplotlib")
527527
else:
528528
configdir = Path.home() / ".matplotlib"
529+
# Resolve the path to handle potential issues with inaccessible symlinks.
530+
configdir = configdir.resolve()
529531
try:
530532
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)
533535
else:
534536
if os.access(str(configdir), os.W_OK) and configdir.is_dir():
535537
return str(configdir)
538+
_log.warning("%s is not a writable directory", configdir)
536539
# If the config or cache directory cannot be created or is not a writable
537540
# directory, create a temporary one.
538541
try:
539542
tmpdir = tempfile.mkdtemp(prefix="matplotlib-")
540543
except OSError as exc:
541544
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 "
544547
f"directory could not be created; set the MPLCONFIGDIR environment "
545548
f"variable to a writable directory") from exc
546549
os.environ["MPLCONFIGDIR"] = tmpdir
547550
atexit.register(shutil.rmtree, tmpdir)
548551
_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 "
551554
"MPLCONFIGDIR environment variable to a writable directory, in particular to "
552555
"speed up the import of Matplotlib and to better support multiprocessing.",
553556
tmpdir, configdir)

0 commit comments

Comments
 (0)