Skip to content

Get default params from matplotlibrc.template. #14929

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
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
1 change: 0 additions & 1 deletion .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ per-file-ignores =
lib/matplotlib/_mathtext_data.py: E203, E261
lib/matplotlib/font_manager.py: E203, E221, E251, E501
lib/matplotlib/mathtext.py: E221, E251
lib/matplotlib/rcsetup.py: E501
lib/matplotlib/tests/test_mathtext.py: E501
lib/matplotlib/transforms.py: E201, E202, E203
lib/matplotlib/tri/triinterpolate.py: E201, E221
Expand Down
49 changes: 27 additions & 22 deletions lib/matplotlib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@
from matplotlib.cbook import (
MatplotlibDeprecationWarning, dedent, get_label, sanitize_sequence)
from matplotlib.cbook import mplDeprecation # deprecated
from matplotlib.rcsetup import defaultParams, validate_backend, cycler
from matplotlib.rcsetup import validate_backend, cycler

import numpy

Expand Down Expand Up @@ -614,7 +614,8 @@ def get_cachedir():
return _get_config_or_cache_dir(_get_xdg_cache_dir())


def _get_data_path():
@_logged_cached('matplotlib data path: %s')
def get_data_path():
"""Return the path to matplotlib data."""

if 'MATPLOTLIBDATA' in os.environ:
Expand Down Expand Up @@ -655,13 +656,6 @@ def get_candidate_paths():
raise RuntimeError('Could not find the matplotlib data files')


@_logged_cached('matplotlib data path: %s')
def get_data_path():
if defaultParams['datapath'][0] is None:
defaultParams['datapath'][0] = _get_data_path()
return defaultParams['datapath'][0]


@cbook.deprecated("3.1")
def get_py2exe_datafiles():
data_path = Path(get_data_path())
Expand Down Expand Up @@ -749,9 +743,7 @@ class RcParams(MutableMapping, dict):
:ref:`customizing-with-matplotlibrc-files`
"""

validate = {key: converter
for key, (default, converter) in defaultParams.items()
if key not in _all_deprecated}
validate = rcsetup._validators

# validate values on the way in
def __init__(self, *args, **kwargs):
Expand Down Expand Up @@ -807,6 +799,9 @@ def __getitem__(self, key):
from matplotlib import pyplot as plt
plt.switch_backend(rcsetup._auto_backend_sentinel)

elif key == "datapath":
return get_data_path()

return dict.__getitem__(self, key)

def __repr__(self):
Expand Down Expand Up @@ -916,7 +911,7 @@ def _rc_params_in_file(fname, fail_on_error=False):
config = RcParams()

for key, (val, line, line_no) in rc_temp.items():
if key in defaultParams:
if key in rcsetup._validators:
if fail_on_error:
config[key] = val # try to convert to proper type or raise
else:
Expand Down Expand Up @@ -962,11 +957,8 @@ def rc_params_from_file(fname, fail_on_error=False, use_default_template=True):
if not use_default_template:
return config_from_file

iter_params = defaultParams.items()
with cbook._suppress_matplotlib_deprecation_warning():
config = RcParams([(key, default) for key, (default, _) in iter_params
if key not in _all_deprecated])
config.update(config_from_file)
config = RcParams({**rcParamsDefault, **config_from_file})

if config['datapath'] is None:
config['datapath'] = get_data_path()
Expand All @@ -984,15 +976,28 @@ def rc_params_from_file(fname, fail_on_error=False, use_default_template=True):
return config


# this is the instance used by the matplotlib classes
rcParams = rc_params()
# When constructing the global instances, we need to perform certain updates
# by explicitly calling the superclass (dict.update, dict.items) to avoid
# triggering resolution of _auto_backend_sentinel.

rcParamsDefault = _rc_params_in_file(
cbook._get_data_path("matplotlibrc"), fail_on_error=True)
with cbook._suppress_matplotlib_deprecation_warning():
dict.update(rcParamsDefault, rcsetup._hardcoded_defaults)

rcParams = RcParams() # The global instance.
with cbook._suppress_matplotlib_deprecation_warning():
dict.update(rcParams, dict.items(rcParamsDefault))
dict.update(rcParams, _rc_params_in_file(matplotlib_fname()))

with cbook._suppress_matplotlib_deprecation_warning():
defaultParams = rcsetup.defaultParams = { # Left only for backcompat.
# We want to resolve deprecated rcParams, but not backend...
key: [(rcsetup._auto_backend_sentinel if key == "backend" else
rcParamsDefault[key]),
validator]
for key, validator in rcsetup._validators.items()}
rcParamsOrig = RcParams(rcParams.copy())
rcParamsDefault = RcParams([(key, default) for key, (default, converter) in
defaultParams.items()
if key not in _all_deprecated])

if rcParams['axes.formatter.use_locale']:
locale.setlocale(locale.LC_ALL, '')
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/cbook/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ def get_sample_data(fname, asfileobj=True):

If the filename ends in .gz, the file is implicitly ungzipped.
"""
path = Path(matplotlib._get_data_path(), 'sample_data', fname)
path = _get_data_path('sample_data', fname)
if asfileobj:
suffix = path.suffix.lower()
if suffix == '.gz':
Expand Down
Loading