Skip to content

Commit 92c50d1

Browse files
committed
Merge pull request matplotlib#4343 from sohero/patch-1
FIX : decode the execution path string based file system encoding Prevents issues on systems with mixed encodings.
2 parents e71d50a + 148b29d commit 92c50d1

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

lib/matplotlib/__init__.py

+12-3
Original file line numberDiff line numberDiff line change
@@ -653,6 +653,13 @@ def _get_cachedir():
653653
get_cachedir = verbose.wrap('CACHEDIR=%s', _get_cachedir, always=False)
654654

655655

656+
def _decode_filesystem_path(path):
657+
if isinstance(path, bytes):
658+
return path.decode(sys.getfilesystemencoding())
659+
else:
660+
return path
661+
662+
656663
def _get_data_path():
657664
'get the path to matplotlib data'
658665

@@ -663,20 +670,22 @@ def _get_data_path():
663670
'directory')
664671
return path
665672

666-
path = os.sep.join([os.path.dirname(__file__), 'mpl-data'])
673+
_file = _decode_filesystem_path(__file__)
674+
path = os.sep.join([os.path.dirname(_file), 'mpl-data'])
667675
if os.path.isdir(path):
668676
return path
669677

670678
# setuptools' namespace_packages may highjack this init file
671679
# so need to try something known to be in matplotlib, not basemap
672680
import matplotlib.afm
673-
path = os.sep.join([os.path.dirname(matplotlib.afm.__file__), 'mpl-data'])
681+
_file = _decode_filesystem_path(matplotlib.afm.__file__)
682+
path = os.sep.join([os.path.dirname(_file), 'mpl-data'])
674683
if os.path.isdir(path):
675684
return path
676685

677686
# py2exe zips pure python, so still need special check
678687
if getattr(sys, 'frozen', None):
679-
exe_path = os.path.dirname(sys.executable)
688+
exe_path = os.path.dirname(_decode_filesystem_path(sys.executable))
680689
path = os.path.join(exe_path, 'mpl-data')
681690
if os.path.isdir(path):
682691
return path

0 commit comments

Comments
 (0)