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
@@ -619,9 +620,31 @@ def get_cachedir():
619
620
return _get_config_or_cache_dir (_get_xdg_cache_dir ())
620
621
621
622
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 ()
624
644
645
+
646
+ @_logged_cached ('(private) matplotlib data path: %s' )
647
+ def _get_data_path ():
625
648
if 'MATPLOTLIBDATA' in os .environ :
626
649
path = os .environ ['MATPLOTLIBDATA' ]
627
650
if not os .path .isdir (path ):
@@ -633,6 +656,7 @@ def _get_data_path():
633
656
634
657
path = Path (__file__ ).with_name ("mpl-data" )
635
658
if path .is_dir ():
659
+ defaultParams ['datapath' ][0 ] = str (path )
636
660
return str (path )
637
661
638
662
cbook .warn_deprecated (
@@ -655,18 +679,12 @@ def get_candidate_paths():
655
679
656
680
for path in get_candidate_paths ():
657
681
if path .is_dir ():
682
+ defaultParams ['datapath' ][0 ] = str (path )
658
683
return str (path )
659
684
660
685
raise RuntimeError ('Could not find the matplotlib data files' )
661
686
662
687
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
-
670
688
@cbook .deprecated ("3.1" )
671
689
def get_py2exe_datafiles ():
672
690
data_path = Path (get_data_path ())
@@ -708,7 +726,7 @@ def gen_candidates():
708
726
yield matplotlibrc
709
727
yield os .path .join (matplotlibrc , 'matplotlibrc' )
710
728
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' )
712
730
713
731
for fname in gen_candidates ():
714
732
if os .path .exists (fname ) and not os .path .isdir (fname ):
@@ -736,6 +754,7 @@ def gen_candidates():
736
754
'savefig.frameon' : ('3.1' ,),
737
755
'verbose.fileo' : ('3.1' ,),
738
756
'verbose.level' : ('3.1' ,),
757
+ 'datapath' : ('3.2.1' ,),
739
758
}
740
759
741
760
@@ -973,8 +992,11 @@ def rc_params_from_file(fname, fail_on_error=False, use_default_template=True):
973
992
if key not in _all_deprecated ])
974
993
config .update (config_from_file )
975
994
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' ])
978
1000
979
1001
if "" .join (config ['text.latex.preamble' ]):
980
1002
_log .info ("""
0 commit comments