Skip to content

Replace most uses of getfilesystemencoding by os.fs{en,de}code. #10513

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 17 additions & 36 deletions lib/matplotlib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand All @@ -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')

Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/backends/backend_pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
6 changes: 2 additions & 4 deletions lib/matplotlib/backends/backend_ps.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
1 change: 0 additions & 1 deletion lib/matplotlib/dviread.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import re
import struct
import subprocess
import sys
import textwrap

import numpy as np
Expand Down