@@ -652,6 +652,11 @@ def _get_cachedir():
652
652
653
653
get_cachedir = verbose .wrap ('CACHEDIR=%s' , _get_cachedir , always = False )
654
654
655
+ def _decode_filesystem_path (path ):
656
+ if isinstance (path , bytes ):
657
+ return path .decode (sys .getfilesystemencoding ())
658
+ else :
659
+ return path
655
660
656
661
def _get_data_path ():
657
662
'get the path to matplotlib data'
@@ -662,33 +667,23 @@ def _get_data_path():
662
667
raise RuntimeError ('Path in environment MATPLOTLIBDATA not a '
663
668
'directory' )
664
669
return path
665
-
666
- if hasattr (__file__ , 'decode' ):
667
- _file = __file__ .decode (sys .getfilesystemencoding ())
668
- else :
669
- _file = __file__
670
+
671
+ _file = _decode_filesystem_path (__file__ )
670
672
path = os .sep .join ([os .path .dirname (_file ), 'mpl-data' ])
671
673
if os .path .isdir (path ):
672
674
return path
673
675
674
676
# setuptools' namespace_packages may highjack this init file
675
677
# so need to try something known to be in matplotlib, not basemap
676
678
import matplotlib .afm
677
- if hasattr (matplotlib .afm .__file__ , 'decode' ):
678
- _file = matplotlib .afm .__file__ .decode (sys .getfilesystemencoding ())
679
- else :
680
- _file = matplotlib .afm .__file__
679
+ _file = _decode_filesystem_path (matplotlib .afm .__file__ )
681
680
path = os .sep .join ([os .path .dirname (_file ), 'mpl-data' ])
682
681
if os .path .isdir (path ):
683
682
return path
684
683
685
684
# py2exe zips pure python, so still need special check
686
685
if getattr (sys , 'frozen' , None ):
687
- if hasattr (sys .executable , 'decode' ):
688
- _file = sys .executable .decode (sys .getfilesystemencoding ())
689
- else :
690
- _file = sys .executable
691
- exe_path = os .path .dirname (_file )
686
+ exe_path = os .path .dirname (_decode_filesystem_path (sys .executable ))
692
687
path = os .path .join (exe_path , 'mpl-data' )
693
688
if os .path .isdir (path ):
694
689
return path
0 commit comments