10000 Hide rc_params_in_file from parent namespace · matplotlib/matplotlib@5fdc037 · GitHub
[go: up one dir, main page]

Skip to content

Commit 5fdc037

Browse files
committed
Hide rc_params_in_file from parent namespace
1 parent ec6ce6b commit 5fdc037

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

lib/matplotlib/__init__.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -906,7 +906,7 @@ def _open_file_or_url(fname):
906906
_error_details_fmt = 'line #%d\n\t"%s"\n\tin file "%s"'
907907

908908

909-
def rc_params_in_file(fname, fail_on_error=False):
909+
def _rc_params_in_file(fname, fail_on_error=False):
910910
"""Return :class:`matplotlib.RcParams` from the contents of the given file.
911911
912912
Unlike `rc_params_from_file`, the configuration class only contains the
@@ -973,7 +973,7 @@ def rc_params_in_file(fname, fail_on_error=False):
973973
return config
974974

975975

976-
def rc_params_from_file(fname, fail_on_error=False):
976+
def rc_params_from_file(fname, fail_on_error=False, use_default_template=True):
977977
"""Return :class:`matplotlib.RcParams` from the contents of the given file.
978978
979979
Parameters
@@ -982,12 +982,19 @@ def rc_params_from_file(fname, fail_on_error=False):
982982
Name of file parsed for matplotlib settings.
983983
fail_on_error : bool
984984
If True, raise an error when the parser fails to convert a parameter.
985+
use_default_template : bool
986+
If True, initialize with default parameters before updating with those
987+
in the given file. If False, the configuration class only contains the
988+
parameters specified in the file. (Useful for updating dicts.)
985989
"""
990+
config_from_file = _rc_params_in_file(fname, fail_on_error)
986991

987-
config = RcParams([(key, default)
988-
for key, (default, _) in six.iteritems(defaultParams)])
992+
if not use_default_template:
993+
return config_from_file
989994

990-
config.update(rc_params_in_file(fname, fail_on_error))
995+
iter_params = six.iteritems(defaultParams)
996+
config = RcParams([(key, default) for key, (default, _) in iter_params])
997+
config.update(config_from_file)
991998

992999
verbose.set_level(config['verbose.level'])
9931000
verbose.set_fileo(config['verbose.fileo'])

lib/matplotlib/style/core.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
import matplotlib as mpl
1818
from matplotlib import cbook
19+
from matplotlib import rc_params_from_file
1920

2021

2122
__all__ = ['use', 'context', 'available', 'library', 'reload_library']
@@ -49,7 +50,7 @@ def use(name):
4950

5051
for style in name:
5152
if is_style_file(style):
52-
settings = mpl.rc_params_in_file(style)
53+
settings = rc_params_from_file(style, use_default_template=False)
5354
mpl.rcParams.update(settings)
5455
elif style not in library:
5556
msg = ("'%s' not found in the style library. "
@@ -117,7 +118,7 @@ def read_style_directory(style_dir):
117118
"""Return dictionary of styles defined in `style_dir`."""
118119
styles = dict()
119120
for path, name in iter_style_files(style_dir):
120-
styles[name] = mpl.rc_params_in_file(path)
121+
styles[name] = rc_params_from_file(path, use_default_template=False)
121122
return styles
122123

123124

0 commit comments

Comments
 (0)
0