132132import shutil
133133import subprocess
134134import 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
@@ -619,9 +620,31 @@ def get_cachedir():
619620 return _get_config_or_cache_dir (_get_xdg_cache_dir ())
620621
621622
622- def _get_data_path ():
623- """Return the path to matplotlib data."""
623+ @_logged_cached ('matplotlib data path: %s' )
624+ def get_data_path (* , _from_rc = None ):
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 ()
624644
645+
646+ @_logged_cached ('(private) matplotlib data path: %s' )
647+ def _get_data_path ():
625648 if 'MATPLOTLIBDATA' in os .environ :
626649 path = os .environ ['MATPLOTLIBDATA' ]
627650 if not os .path .isdir (path ):
@@ -633,6 +656,7 @@ def _get_data_path():
633656
634657 path = Path (__file__ ).with_name ("mpl-data" )
635658 if path .is_dir ():
659+ defaultParams ['datapath' ][0 ] = str (path )
636660 return str (path )
637661
638662 cbook .warn_deprecated (
@@ -655,18 +679,12 @@ def get_candidate_paths():
655679
656680 for path in get_candidate_paths ():
657681 if path .is_dir ():
682+ defaultParams ['datapath' ][0 ] = str (path )
658683 return str (path )
659684
660685 raise RuntimeError ('Could not find the matplotlib data files' )
661686
662687
663- @_logged_cached ('matplotlib data path: %s' )
664- def get_data_path ():
665- if defaultParams ['datapath' ][0 ] is None :
666- defaultParams ['datapath' ][0 ] = _get_data_path ()
667- return defaultParams ['datapath' ][0 ]
668-
669-
670688@cbook .deprecated ("3.1" )
671689def get_py2exe_datafiles ():
672690 data_path = Path (get_data_path ())
@@ -708,7 +726,7 @@ def gen_candidates():
708726 yield matplotlibrc
709727 yield os .path .join (matplotlibrc , 'matplotlibrc' )
710728 yield os .path .join (get_configdir (), 'matplotlibrc' )
711- yield os .path .join (get_data_path (), 'matplotlibrc' )
729+ yield os .path .join (_get_data_path (), 'matplotlibrc' )
712730
713731 for fname in gen_candidates ():
714732 if os .path .exists (fname ) and not os .path .isdir (fname ):
@@ -736,6 +754,7 @@ def gen_candidates():
736754 'savefig.frameon' : ('3.1' ,),
737755 'verbose.fileo' : ('3.1' ,),
738756 'verbose.level' : ('3.1' ,),
757+ 'datapath' : ('3.2.1' ,),
739758}
740759
741760
@@ -973,8 +992,11 @@ def rc_params_from_file(fname, fail_on_error=False, use_default_template=True):
973992 if key not in _all_deprecated ])
974993 config .update (config_from_file )
975994
976- if config ['datapath' ] is None :
977- config ['datapath' ] = get_data_path ()
995+ with cbook ._suppress_matplotlib_deprecation_warning ():
996+ if config ['datapath' ] is None :
997+ config ['datapath' ] = _get_data_path ()
998+ else :
999+ config ['datapath' ] = get_data_path (_from_rc = config ['datapath' ])
9781000
9791001 if "" .join (config ['text.latex.preamble' ]):
9801002 _log .info ("""
0 commit comments