@@ -386,27 +386,22 @@ def ge(self, level):
386
386
verbose = Verbose ()
387
387
388
388
389
- def _wrap (fmt , func , level = logging .DEBUG , always = True ):
390
- """
391
- return a callable function that wraps func and reports its
392
- output through logger
393
-
394
- if always is True, the report will occur on every function
395
- call; otherwise only on the first time the function is called
396
- """
397
- assert callable (func )
398
-
399
- def wrapper (* args , ** kwargs ):
400
- ret = func (* args , ** kwargs )
401
-
402
- if (always or not wrapper ._spoke ):
403
- _log .log (level , fmt % ret )
404
- spoke = True
405
- if not wrapper ._spoke :
406
- wrapper ._spoke = spoke
389
+ def _logged_cached (fmt , func = None ):
390
+ if func is None :
391
+ return functools .partial (_logged_cached , fmt )
392
+
393
+ called = False
394
+ ret = None
395
+
396
+ @functools .wraps (func )
397
+ def wrapper ():
398
+ nonlocal called , ret
399
+ if not called :
400
+ ret = func ()
401
+ called = True
402
+ _log .debug (fmt , ret )
407
403
return ret
408
- wrapper ._spoke = False
409
- wrapper .__doc__ = func .__doc__
404
+
410
405
return wrapper
411
406
412
407
@@ -544,7 +539,8 @@ def checkdep_usetex(s):
544
539
return flag
545
540
546
541
547
- def _get_home ():
542
+ @_logged_cached ('$HOME=%s' )
543
+ def get_home ():
548
544
"""
549
545
Return the user's home directory.
550
546
@@ -555,8 +551,6 @@ def _get_home():
555
551
except Exception :
556
552
return None
557
553
558
- get_home = _wrap ('$HOME=%s' , _get_home , always = False )
559
-
560
554
561
555
def _create_tmp_config_dir ():
562
556
"""
@@ -615,7 +609,8 @@ def _get_config_or_cache_dir(xdg_base):
615
609
return _create_tmp_config_dir ()
616
610
617
611
618
- def _get_configdir ():
612
+ @_logged_cached ('CONFIGDIR=%s' )
613
+ def get_configdir ():
619
614
"""
620
615
Return the string representing the configuration directory.
621
616
@@ -633,10 +628,9 @@ def _get_configdir():
633
628
"""
634
629
return _get_config_or_cache_dir (_get_xdg_config_dir ())
635
630
636
- get_configdir = _wrap ('CONFIGDIR=%s' , _get_configdir , always = False )
637
-
638
631
639
- def _get_cachedir ():
632
+ @_logged_cached ('CACHEDIR=%s' )
633
+ def get_cachedir ():
640
634
"""
641
635
Return the location of the cache directory.
642
636
@@ -645,8 +639,6 @@ def _get_cachedir():
645
639
"""
646
640
return _get_config_or_cache_dir (_get_xdg_cache_dir ())
647
641
648
- get_cachedir = _wrap ('CACHEDIR=%s' , _get_cachedir , always = False )
649
-
650
642
651
643
def _decode_filesystem_path (path ):
652
644
if not isinstance (path , str ):
@@ -698,14 +690,12 @@ def _get_data_path():
698
690
raise RuntimeError ('Could not find the matplotlib data files' )
699
691
700
692
701
- def _get_data_path_cached ():
693
+ @_logged_cached ('matplotlib data path: %s' )
694
+ def get_data_path ():
702
695
if defaultParams ['datapath' ][0 ] is None :
703
696
defaultParams ['datapath' ][0 ] = _get_data_path ()
704
697
return defaultParams ['datapath' ][0 ]
705
698
706
- get_data_path = _wrap ('matplotlib data path %s' , _get_data_path_cached ,
707
- always = False )
708
-
709
699
710
700
def get_py2exe_datafiles ():
711
701
data_path = Path (get_data_path ())
@@ -756,7 +746,7 @@ def gen_candidates():
756
746
else :
757
747
yield matplotlibrc
758
748
yield os .path .join (matplotlibrc , 'matplotlibrc' )
759
- yield os .path .join (_get_configdir (), 'matplotlibrc' )
749
+ yield os .path .join (get_configdir (), 'matplotlibrc' )
760
750
yield os .path .join (get_data_path (), 'matplotlibrc' )
761
751
762
752
for fname in gen_candidates ():
0 commit comments