|
132 | 132 | import shutil
|
133 | 133 | import subprocess
|
134 | 134 | import tempfile
|
| 135 | +import warnings |
135 | 136 |
|
136 | 137 | # cbook must import matplotlib only within function
|
137 | 138 | # definitions, so it is safe to import from it here.
|
@@ -269,10 +270,10 @@ def func(): ...
|
269 | 270 | ret = None
|
270 | 271 |
|
271 | 272 | @functools.wraps(func)
|
272 |
| - def wrapper(): |
| 273 | + def wrapper(**kwargs): |
273 | 274 | nonlocal called, ret
|
274 | 275 | if not called:
|
275 |
| - ret = func() |
| 276 | + ret = func(**kwargs) |
276 | 277 | called = True
|
277 | 278 | _log.debug(fmt, ret)
|
278 | 279 | return ret
|
@@ -620,9 +621,30 @@ def get_cachedir():
|
620 | 621 |
|
621 | 622 |
|
622 | 623 | @_logged_cached('matplotlib data path: %s')
|
623 |
| -def get_data_path(): |
| 624 | +def get_data_path(*, _from_rc=None): |
624 | 625 | """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() |
625 | 644 |
|
| 645 | + |
| 646 | +@_logged_cached('(private) matplotlib data path: %s') |
| 647 | +def _get_data_path(): |
626 | 648 | if 'MATPLOTLIBDATA' in os.environ:
|
627 | 649 | path = os.environ['MATPLOTLIBDATA']
|
628 | 650 | if not os.path.isdir(path):
|
@@ -704,7 +726,7 @@ def gen_candidates():
|
704 | 726 | yield matplotlibrc
|
705 | 727 | yield os.path.join(matplotlibrc, 'matplotlibrc')
|
706 | 728 | 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') |
708 | 730 |
|
709 | 731 | for fname in gen_candidates():
|
710 | 732 | 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):
|
972 | 994 |
|
973 | 995 | with cbook._suppress_matplotlib_deprecation_warning():
|
974 | 996 | 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']) |
976 | 1000 |
|
977 | 1001 | if "".join(config['text.latex.preamble']):
|
978 | 1002 | _log.info("""
|
|
0 commit comments