Skip to content

Commit 7ef113b

Browse files
committed
Be less tolerant of broken installs.
If no user-defined matplotlibrc is present, require it to exists in mpl-data. (We already throw when mpl-data cannot be found -- which is also a sign of broken install -- so it's not much worse to require matplotlibrc to exist as well.)
1 parent 70a55db commit 7ef113b

File tree

1 file changed

+16
-35
lines changed

1 file changed

+16
-35
lines changed

lib/matplotlib/__init__.py

+16-35
Original file line numberDiff line numberDiff line change
@@ -697,28 +697,19 @@ def matplotlib_fname():
697697
698698
The file location is determined in the following order
699699
700-
- `$PWD/matplotlibrc`
701-
702-
- `$MATPLOTLIBRC` if it is not a directory
703-
704-
- `$MATPLOTLIBRC/matplotlibrc`
705-
706-
- `$MPLCONFIGDIR/matplotlibrc`
707-
700+
- ``$PWD/matplotlibrc``
701+
- ``$MATPLOTLIBRC`` if it is not a directory
702+
- ``$MATPLOTLIBRC/matplotlibrc``
703+
- ``$MPLCONFIGDIR/matplotlibrc``
708704
- On Linux,
709-
710-
- `$XDG_CONFIG_HOME/matplotlib/matplotlibrc` (if
711-
$XDG_CONFIG_HOME is defined)
712-
713-
- or `$HOME/.config/matplotlib/matplotlibrc` (if
714-
$XDG_CONFIG_HOME is not defined)
715-
705+
- ``$XDG_CONFIG_HOME/matplotlib/matplotlibrc`` (if ``$XDG_CONFIG_HOME``
706+
is defined)
707+
- or ``$HOME/.config/matplotlib/matplotlibrc`` (if ``$XDG_CONFIG_HOME``
708+
is not defined)
716709
- On other platforms,
717-
718-
- `$HOME/.matplotlib/matplotlibrc` if `$HOME` is defined.
719-
720-
- Lastly, it looks in `$MATPLOTLIBDATA/matplotlibrc` for a
721-
system-defined copy.
710+
- ``$HOME/.matplotlib/matplotlibrc`` if ``$HOME`` is defined
711+
- Lastly, it looks in ``$MATPLOTLIBDATA/matplotlibrc``, which should always
712+
exist.
722713
"""
723714

724715
def gen_candidates():
@@ -735,10 +726,10 @@ def gen_candidates():
735726

736727
for fname in gen_candidates():
737728
if os.path.exists(fname) and not os.path.isdir(fname):
738-
break
739-
# Return first candidate that is a file, or last candidate if none is
740-
# valid (in that case, a warning is raised at startup by `rc_params`).
741-
return fname
729+
return fname
730+
731+
raise RuntimeError("Could not find matplotlibrc file; your Matplotlib "
732+
"install is broken")
742733

743734

744735
# rcParams deprecated and automatically mapped to another key.
@@ -917,17 +908,7 @@ def rc_params(fail_on_error=False):
917908
"""Return a :class:`matplotlib.RcParams` instance from the
918909
default matplotlib rc file.
919910
"""
920-
fname = matplotlib_fname()
921-
if not os.path.exists(fname):
922-
# this should never happen, default in mpl-data should always be found
923-
message = 'could not find rc file; returning defaults'
924-
ret = RcParams([(key, default) for key, (default, _) in
925-
defaultParams.items()
926-
if key not in _all_deprecated])
927-
warnings.warn(message)
928-
return ret
929-
930-
return rc_params_from_file(fname, fail_on_error)
911+
return rc_params_from_file(matplotlib_fname(), fail_on_error)
931912

932913

933914
URL_REGEX = re.compile(r'http://|https://|ftp://|file://|file:\\')

0 commit comments

Comments
 (0)