From 6447ff668654cb8954cc9bd46137f78d40b886d2 Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Wed, 25 Oct 2017 00:39:33 -0700 Subject: [PATCH] Allow setting MATPLOTLIBRC by process substitution. This makes (e.g.) ``` $ MATPLOTLIBRC=<(echo 'savefig.transparent: true') python foo.py ``` use `savefig.transparent: true` as contents of matplotlibrc for the given process (on POSIX). This generalizes the MPLBACKEND mechanism to all rcParams (although the lack of "cascading" rc-files means that the "normal" rc-file is completely hidden). --- lib/matplotlib/__init__.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/matplotlib/__init__.py b/lib/matplotlib/__init__.py index 846c08d1c32f..a55e205a40cb 100644 --- a/lib/matplotlib/__init__.py +++ b/lib/matplotlib/__init__.py @@ -118,6 +118,7 @@ import os import re import shutil +import stat import sys import tempfile import warnings @@ -798,7 +799,8 @@ def matplotlib_fname(): - `$PWD/matplotlibrc` - - `$MATPLOTLIBRC` if it is a file + - `$MATPLOTLIBRC` if it is a file (or a named pipe, which can be created + e.g. by process substitution) - `$MATPLOTLIBRC/matplotlibrc` @@ -833,8 +835,10 @@ def gen_candidates(): yield os.path.join(get_data_path(), 'matplotlibrc') for fname in gen_candidates(): - if os.path.isfile(fname): - break + 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 # 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