Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 89d18d8

Browse filesBrowse files
committed
Print warning when mkdir fails instead of silently ignoring the error
See https://stackoverflow.com/questions/5833623/mplconfigdir-error-in-matplotlib for an example where someone had no disk space, causing mkdir to fail, but didn't realize it because the error was silently discarded, and the subsequent warning only mentioned access issues.
1 parent 957271f commit 89d18d8
Copy full SHA for 89d18d8

File tree

Expand file treeCollapse file tree

1 file changed

+5
-4
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+5
-4
lines changed

‎lib/matplotlib/__init__.py

Copy file name to clipboardExpand all lines: lib/matplotlib/__init__.py
+5-4Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -530,26 +530,27 @@ def _get_config_or_cache_dir(xdg_base_getter):
530530
configdir = configdir.resolve()
531531
try:
532532
configdir.mkdir(parents=True, exist_ok=True)
533-
except OSError:
534-
pass
533+
except OSError as exc:
534+
_log.warning("mkdir -p failed for path %s: %s", configdir, exc)
535535
else:
536536
if os.access(str(configdir), os.W_OK) and configdir.is_dir():
537537
return str(configdir)
538+
_log.warning("%s is not a writable directory", configdir)
538539
# If the config or cache directory cannot be created or is not a writable
539540
# directory, create a temporary one.
540541
try:
541542
tmpdir = tempfile.mkdtemp(prefix="matplotlib-")
542543
except OSError as exc:
543544
raise OSError(
544545
f"Matplotlib requires access to a writable cache directory, but the "
545-
f"default path ({configdir}) is not a writable directory, and a temporary "
546+
f"default path ({configdir}) is inaccessible, and a temporary "
546547
f"directory could not be created; set the MPLCONFIGDIR environment "
547548
f"variable to a writable directory") from exc
548549
os.environ["MPLCONFIGDIR"] = tmpdir
549550
atexit.register(shutil.rmtree, tmpdir)
550551
_log.warning(
551552
"Matplotlib created a temporary cache directory at %s because the default path "
552-
"(%s) is not a writable directory; it is highly recommended to set the "
553+
"(%s) is inaccessible; it is highly recommended to set the "
553554
"MPLCONFIGDIR environment variable to a writable directory, in particular to "
554555
"speed up the import of Matplotlib and to better support multiprocessing.",
555556
tmpdir, configdir)

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.