Skip to content

Commit 6edc7a8

Browse files
authored
Merge pull request #10513 from anntzer/fsencodedecode
MNT: Replace most uses of getfilesystemencoding by os.fs{en,de}code.
2 parents 324a8af + e981876 commit 6edc7a8

File tree

4 files changed

+20
-42
lines changed

4 files changed

+20
-42
lines changed

lib/matplotlib/__init__.py

Lines changed: 17 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -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-
663656
def _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

lib/matplotlib/backends/backend_pdf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -970,7 +970,7 @@ def get_char_width(charcode):
970970
# Make the charprocs array (using ttconv to generate the
971971
# actual outlines)
972972
rawcharprocs = ttconv.get_pdf_charprocs(
973-
filename.encode(sys.getfilesystemencoding()), glyph_ids)
973+
os.fsencode(filename), glyph_ids)
974974
charprocs = {}
975975
for charname in sorted(rawcharprocs):
976976
stream = rawcharprocs[charname]

lib/matplotlib/backends/backend_ps.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1118,10 +1118,8 @@ def print_figure_impl(fh):
11181118
"time; consider using the Cairo backend")
11191119
else:
11201120
fh.flush()
1121-
convert_ttf_to_ps(
1122-
font_filename.encode(
1123-
sys.getfilesystemencoding()),
1124-
fh, fonttype, glyph_ids)
1121+
convert_ttf_to_ps(os.fsencode(font_filename),
1122+
fh, fonttype, glyph_ids)
11251123
print("end", file=fh)
11261124
print("%%EndProlog", file=fh)
11271125

lib/matplotlib/dviread.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import re
2626
import struct
2727
import subprocess
28-
import sys
2928
import textwrap
3029

3130
import numpy as np

0 commit comments

Comments
 (0)