Skip to content

Be less tolerant of broken installs. #12246

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 11, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 16 additions & 35 deletions lib/matplotlib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -697,28 +697,19 @@ def matplotlib_fname():

The file location is determined in the following order

- `$PWD/matplotlibrc`

- `$MATPLOTLIBRC` if it is not a directory

- `$MATPLOTLIBRC/matplotlibrc`

- `$MPLCONFIGDIR/matplotlibrc`

- ``$PWD/matplotlibrc``
- ``$MATPLOTLIBRC`` if it is not a directory
- ``$MATPLOTLIBRC/matplotlibrc``
- ``$MPLCONFIGDIR/matplotlibrc``
- On Linux,

- `$XDG_CONFIG_HOME/matplotlib/matplotlibrc` (if
$XDG_CONFIG_HOME is defined)

- or `$HOME/.config/matplotlib/matplotlibrc` (if
$XDG_CONFIG_HOME is not defined)

- ``$XDG_CONFIG_HOME/matplotlib/matplotlibrc`` (if ``$XDG_CONFIG_HOME``
is defined)
- or ``$HOME/.config/matplotlib/matplotlibrc`` (if ``$XDG_CONFIG_HOME``
is not defined)
- On other platforms,

- `$HOME/.matplotlib/matplotlibrc` if `$HOME` is defined.

- Lastly, it looks in `$MATPLOTLIBDATA/matplotlibrc` for a
system-defined copy.
- ``$HOME/.matplotlib/matplotlibrc`` if ``$HOME`` is defined
- Lastly, it looks in ``$MATPLOTLIBDATA/matplotlibrc``, which should always
exist.
"""

def gen_candidates():
Expand All @@ -735,10 +726,10 @@ def gen_candidates():

for fname in gen_candidates():
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
return fname

raise RuntimeError("Could not find matplotlibrc file; your Matplotlib "
"install is broken")


# rcParams deprecated and automatically mapped to another key.
Expand Down Expand Up @@ -917,17 +908,7 @@ def rc_params(fail_on_error=False):
"""Return a :class:`matplotlib.RcParams` instance from the
default matplotlib rc file.
"""
fname = matplotlib_fname()
if not os.path.exists(fname):
# this should never happen, default in mpl-data should always be found
message = 'could not find rc file; returning defaults'
ret = RcParams([(key, default) for key, (default, _) in
defaultParams.items()
if key not in _all_deprecated])
warnings.warn(message)
return ret

return rc_params_from_file(fname, fail_on_error)
return rc_params_from_file(matplotlib_fname(), fail_on_error)


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