Skip to content

Commit 3ba4f5a

Browse files
committed
fix support for python version 3+ and pep8
fix support for python version 3+ and pep8
1 parent 4cb27c0 commit 3ba4f5a

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

lib/matplotlib/__init__.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -663,20 +663,32 @@ def _get_data_path():
663663
'directory')
664664
return path
665665

666-
path = os.sep.join([os.path.dirname(__file__.decode(sys.getfilesystemencoding())), 'mpl-data'])
666+
if hasattr(__file__, 'decode'):
667+
_file=__file__.decode(sys.getfilesystemencoding())
668+
else:
669+
_file=__file__
670+
path = os.sep.join([os.path.dirname(_file), 'mpl-data'])
667671
if os.path.isdir(path):
668672
return path
669673

670674
# setuptools' namespace_packages may highjack this init file
671675
# so need to try something known to be in matplotlib, not basemap
672676
import matplotlib.afm
673-
path = os.sep.join([os.path.dirname(matplotlib.afm.__file__.decode(sys.getfilesystemencoding())), 'mpl-data'])
677+
if hasattr(matplotlib.afm.__file__, 'decode'):
678+
_file=matplotlib.afm.__file__.decode(sys.getfilesystemencoding())
679+
else:
680+
_file=matplotlib.afm.__file__
681+
path = os.sep.join([os.path.dirname(_file), 'mpl-data'])
674682
if os.path.isdir(path):
675683
return path
676684

677685
# py2exe zips pure python, so still need special check
678686
if getattr(sys, 'frozen', None):
679-
exe_path = os.path.dirname(sys.executable.decode(sys.getfilesystemencoding()))
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)
680692
path = os.path.join(exe_path, 'mpl-data')
681693
if os.path.isdir(path):
682694
return path

0 commit comments

Comments
 (0)