Skip to content

Commit 6447ff6

Browse files
committed
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).
1 parent 6336f2d commit 6447ff6

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

lib/matplotlib/__init__.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@
118118
import os
119119
import re
120120
import shutil
121+
import stat
121122
import sys
122123
import tempfile
123124
import warnings
@@ -798,7 +799,8 @@ def matplotlib_fname():
798799
799800
- `$PWD/matplotlibrc`
800801
801-
- `$MATPLOTLIBRC` if it is a file
802+
- `$MATPLOTLIBRC` if it is a file (or a named pipe, which can be created
803+
e.g. by process substitution)
802804
803805
- `$MATPLOTLIBRC/matplotlibrc`
804806
@@ -833,8 +835,10 @@ def gen_candidates():
833835
yield os.path.join(get_data_path(), 'matplotlibrc')
834836

835837
for fname in gen_candidates():
836-
if os.path.isfile(fname):
837-
break
838+
if os.path.exists(fname):
839+
st_mode = os.stat(fname).st_mode
840+
if stat.S_ISREG(st_mode) or stat.S_ISFIFO(st_mode):
841+
break
838842
# Return first candidate that is a file, or last candidate if none is
839843
# valid (in that case, a warning is raised at startup by `rc_params`).
840844
return fname

0 commit comments

Comments
 (0)