Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit ecd95c4

Browse filesBrowse files
committed
MNT: re-instate respecting datapath in matplotlibrc file
Closes #16678 This does a bit of jiggery-pokery to respect the datapath set in the users matplotlibrc. This is going to have an expedited deprecation cycle as we don't think end-users should be setting this rcparam.
1 parent 26ab43e commit ecd95c4
Copy full SHA for ecd95c4

File tree

Expand file treeCollapse file tree

1 file changed

+29
-5
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+29
-5
lines changed

‎lib/matplotlib/__init__.py

Copy file name to clipboardExpand all lines: lib/matplotlib/__init__.py
+29-5Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@
132132
import shutil
133133
import subprocess
134134
import tempfile
135+
import warnings
135136

136137
# cbook must import matplotlib only within function
137138
# definitions, so it is safe to import from it here.
@@ -269,10 +270,10 @@ def func(): ...
269270
ret = None
270271

271272
@functools.wraps(func)
272-
def wrapper():
273+
def wrapper(**kwargs):
273274
nonlocal called, ret
274275
if not called:
275-
ret = func()
276+
ret = func(**kwargs)
276277
called = True
277278
_log.debug(fmt, ret)
278279
return ret
@@ -620,9 +621,30 @@ def get_cachedir():
620621

621622

622623
@_logged_cached('matplotlib data path: %s')
623-
def get_data_path():
624+
def get_data_path(*, _from_rc=None):
624625
"""Return the path to Matplotlib data."""
626+
if _from_rc is not None:
627+
cbook.warn_deprecated(
628+
"3.2",
629+
message=("Setting the datapath via matplotlibrc is "
630+
"deprecated %(since)s and will be removed in %(removal)s. "
631+
""),
632+
removal='3.3')
633+
path = Path(_from_rc)
634+
if path.is_dir():
635+
defaultParams['datapath'][0] = str(path)
636+
return str(path)
637+
else:
638+
warnings.warn(f"You passed datapath: {_from_rc!r} in your "
639+
f"matplotribrc file ({matplotlib_fname()}). "
640+
"However this path does not exist, falling back "
641+
"to standard paths.")
642+
643+
return _get_data_path()
625644

645+
646+
@_logged_cached('(private) matplotlib data path: %s')
647+
def _get_data_path():
626648
if 'MATPLOTLIBDATA' in os.environ:
627649
path = os.environ['MATPLOTLIBDATA']
628650
if not os.path.isdir(path):
@@ -704,7 +726,7 @@ def gen_candidates():
704726
yield matplotlibrc
705727
yield os.path.join(matplotlibrc, 'matplotlibrc')
706728
yield os.path.join(get_configdir(), 'matplotlibrc')
707-
yield os.path.join(get_data_path(), 'matplotlibrc')
729+
yield os.path.join(_get_data_path(), 'matplotlibrc')
708730

709731
for fname in gen_candidates():
710732
if os.path.exists(fname) and not os.path.isdir(fname):
@@ -972,7 +994,9 @@ def rc_params_from_file(fname, fail_on_error=False, use_default_template=True):
972994

973995
with cbook._suppress_matplotlib_deprecation_warning():
974996
if config['datapath'] is None:
975-
config['datapath'] = get_data_path()
997+
config['datapath'] = _get_data_path()
998+
else:
999+
config['datapath'] = get_data_path(_from_rc=config['datapath'])
9761000

9771001
if "".join(config['text.latex.preamble']):
9781002
_log.info("""

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.