From 71326f5755eea1815add5af57238b84658a720e0 Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Wed, 15 Aug 2018 13:03:28 +0200 Subject: [PATCH] Accept anything that's not a directory for $MATPLOTLIBRC. This allows e.g. setting $MATPLOTLIBRC to /dev/null to ignore a local matplotlibrc. --- doc/users/next_whats_new/2018-08-15-AL.rst | 11 +++++++++++ lib/matplotlib/__init__.py | 10 +++------- 2 files changed, 14 insertions(+), 7 deletions(-) create mode 100644 doc/users/next_whats_new/2018-08-15-AL.rst diff --git a/doc/users/next_whats_new/2018-08-15-AL.rst b/doc/users/next_whats_new/2018-08-15-AL.rst new file mode 100644 index 000000000000..f58e0429475f --- /dev/null +++ b/doc/users/next_whats_new/2018-08-15-AL.rst @@ -0,0 +1,11 @@ +:orphan: + +The MATPLOTLIBRC environment variable can now point to any "file" path +`````````````````````````````````````````````````````````````````````` + +This includes device files; in particular, on Unix systems, one can set +``MATPLOTLIBRC`` to ``/dev/null`` to ignore the user's matplotlibrc file and +fall back to Matplotlib's defaults. + +As a reminder, if ``MATPLOTLIBRC`` points to a directory, Matplotlib will try +to load the matplotlibrc file from ``$MATPLOTLIBRC/matplotlibrc``. diff --git a/lib/matplotlib/__init__.py b/lib/matplotlib/__init__.py index 3f2a6a300e30..9fe32e970b1c 100644 --- a/lib/matplotlib/__init__.py +++ b/lib/matplotlib/__init__.py @@ -130,7 +130,6 @@ import pprint import re import shutil -import stat import subprocess import tempfile import urllib.request @@ -708,8 +707,7 @@ def matplotlib_fname(): - `$PWD/matplotlibrc` - - `$MATPLOTLIBRC` if it is a file (or a named pipe, which can be created - e.g. by process substitution) + - `$MATPLOTLIBRC` if it is not a directory - `$MATPLOTLIBRC/matplotlibrc` @@ -744,10 +742,8 @@ def gen_candidates(): yield os.path.join(get_data_path(), 'matplotlibrc') for fname in gen_candidates(): - if os.path.exists(fname): - st_mode = os.stat(fname).st_mode - if stat.S_ISREG(st_mode) or stat.S_ISFIFO(st_mode): - break + if os.path.exists(fname) and not os.path.isdir(fname): + break # Return first candidate that is a file, or last candidate if none is # valid (in that case, a warning is raised at startup by `rc_params`). return fname