diff --git a/lib/matplotlib/__init__.py b/lib/matplotlib/__init__.py index 56a8de8532e0..4923fb9b37f8 100644 --- a/lib/matplotlib/__init__.py +++ b/lib/matplotlib/__init__.py @@ -653,13 +653,6 @@ def get_cachedir(): return _get_config_or_cache_dir(_get_xdg_cache_dir()) -def _decode_filesystem_path(path): - if not isinstance(path, str): - return path.decode(sys.getfilesystemencoding()) - else: - return path - - def _get_data_path(): 'get the path to matplotlib data' @@ -670,35 +663,23 @@ def _get_data_path(): 'directory') return path - _file = _decode_filesystem_path(__file__) - path = os.sep.join([os.path.dirname(_file), 'mpl-data']) - if os.path.isdir(path): - return path - - # setuptools' namespace_packages may highjack this init file - # so need to try something known to be in matplotlib, not basemap - import matplotlib.afm - _file = _decode_filesystem_path(matplotlib.afm.__file__) - path = os.sep.join([os.path.dirname(_file), 'mpl-data']) - if os.path.isdir(path): - return path - - # py2exe zips pure python, so still need special check - if getattr(sys, 'frozen', None): - exe_path = os.path.dirname(_decode_filesystem_path(sys.executable)) - path = os.path.join(exe_path, 'mpl-data') - if os.path.isdir(path): - return path - - # Try again assuming we need to step up one more directory - path = os.path.join(os.path.split(exe_path)[0], 'mpl-data') - if os.path.isdir(path): - return path - - # Try again assuming sys.path[0] is a dir not a exe - path = os.path.join(sys.path[0], 'mpl-data') - if os.path.isdir(path): - return path + def get_candidate_paths(): + yield Path(__file__).with_name('mpl-data') + # setuptools' namespace_packages may highjack this init file + # so need to try something known to be in Matplotlib, not basemap. + import matplotlib.afm + yield Path(matplotlib.afm.__file__).with_name('mpl-data') + # py2exe zips pure python, so still need special check. + if getattr(sys, 'frozen', None): + yield Path(sys.executable).with_name('mpl-data') + # Try again assuming we need to step up one more directory. + yield Path(sys.executable).parent.with_name('mpl-data') + # Try again assuming sys.path[0] is a dir not a exe. + yield Path(sys.path[0]) / 'mpl-data' + + for path in get_candidate_paths(): + if path.is_dir(): + return str(path) raise RuntimeError('Could not find the matplotlib data files') diff --git a/lib/matplotlib/backends/backend_pdf.py b/lib/matplotlib/backends/backend_pdf.py index a8b6a7e8250b..a840f9742f75 100644 --- a/lib/matplotlib/backends/backend_pdf.py +++ b/lib/matplotlib/backends/backend_pdf.py @@ -970,7 +970,7 @@ def get_char_width(charcode): # Make the charprocs array (using ttconv to generate the # actual outlines) rawcharprocs = ttconv.get_pdf_charprocs( - filename.encode(sys.getfilesystemencoding()), glyph_ids) + os.fsencode(filename), glyph_ids) charprocs = {} for charname in sorted(rawcharprocs): stream = rawcharprocs[charname] diff --git a/lib/matplotlib/backends/backend_ps.py b/lib/matplotlib/backends/backend_ps.py index b705fc867ad8..14f549b331e2 100644 --- a/lib/matplotlib/backends/backend_ps.py +++ b/lib/matplotlib/backends/backend_ps.py @@ -1118,10 +1118,8 @@ def print_figure_impl(fh): "time; consider using the Cairo backend") else: fh.flush() - convert_ttf_to_ps( - font_filename.encode( - sys.getfilesystemencoding()), - fh, fonttype, glyph_ids) + convert_ttf_to_ps(os.fsencode(font_filename), + fh, fonttype, glyph_ids) print("end", file=fh) print("%%EndProlog", file=fh) diff --git a/lib/matplotlib/dviread.py b/lib/matplotlib/dviread.py index e99790d3433a..f738fb591d3e 100644 --- a/lib/matplotlib/dviread.py +++ b/lib/matplotlib/dviread.py @@ -25,7 +25,6 @@ import re import struct import subprocess -import sys import textwrap import numpy as np