@@ -653,13 +653,6 @@ def get_cachedir():
653653 return _get_config_or_cache_dir (_get_xdg_cache_dir ())
654654
655655
656- def _decode_filesystem_path (path ):
657- if not isinstance (path , str ):
658- return path .decode (sys .getfilesystemencoding ())
659- else :
660- return path
661-
662-
663656def _get_data_path ():
664657 'get the path to matplotlib data'
665658
@@ -670,35 +663,23 @@ def _get_data_path():
670663 'directory' )
671664 return path
672665
673- _file = _decode_filesystem_path (__file__ )
674- path = os .sep .join ([os .path .dirname (_file ), 'mpl-data' ])
675- if os .path .isdir (path ):
676- return path
677-
678- # setuptools' namespace_packages may highjack this init file
679- # so need to try something known to be in matplotlib, not basemap
680- import matplotlib .afm
681- _file = _decode_filesystem_path (matplotlib .afm .__file__ )
682- path = os .sep .join ([os .path .dirname (_file ), 'mpl-data' ])
683- if os .path .isdir (path ):
684- return path
685-
686- # py2exe zips pure python, so still need special check
687- if getattr (sys , 'frozen' , None ):
688- exe_path = os .path .dirname (_decode_filesystem_path (sys .executable ))
689- path = os .path .join (exe_path , 'mpl-data' )
690- if os .path .isdir (path ):
691- return path
692-
693- # Try again assuming we need to step up one more directory
694- path = os .path .join (os .path .split (exe_path )[0 ], 'mpl-data' )
695- if os .path .isdir (path ):
696- return path
697-
698- # Try again assuming sys.path[0] is a dir not a exe
699- path = os .path .join (sys .path [0 ], 'mpl-data' )
700- if os .path .isdir (path ):
701- return path
666+ def get_candidate_paths ():
667+ yield Path (__file__ ).with_name ('mpl-data' )
668+ # setuptools' namespace_packages may highjack this init file
669+ # so need to try something known to be in Matplotlib, not basemap.
670+ import matplotlib .afm
671+ yield Path (matplotlib .afm .__file__ ).with_name ('mpl-data' )
672+ # py2exe zips pure python, so still need special check.
673+ if getattr (sys , 'frozen' , None ):
674+ yield Path (sys .executable ).with_name ('mpl-data' )
675+ # Try again assuming we need to step up one more directory.
676+ yield Path (sys .executable ).parent .with_name ('mpl-data' )
677+ # Try again assuming sys.path[0] is a dir not a exe.
678+ yield Path (sys .path [0 ]) / 'mpl-data'
679+
680+ for path in get_candidate_paths ():
681+ if path .is_dir ():
682+ return str (path )
702683
703684 raise RuntimeError ('Could not find the matplotlib data files' )
704685
0 commit comments