Skip to content

Commit fa92b90

Browse files
committed
Some minimal changes needed to make python -c 'import matplotlib' work
when the home directory contains non-ASCII characters. This also went ahead and removed unicode_literals from most test modules, opting instead to only use unicode literals explicitly for string literals containing non-ASCII characters (naturally this only impacts Python 2; on Python 3 all strings are unicode literals by default). This has all tests passing still on Python 2/3 *without* non-ASCII home directory.
1 parent 8f3f7ac commit fa92b90

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+146
-230
lines changed

lib/matplotlib/__init__.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,7 @@
9999
to MATLAB®, a registered trademark of The MathWorks, Inc.
100100
101101
"""
102-
from __future__ import (absolute_import, division, print_function,
103-
unicode_literals)
102+
from __future__ import absolute_import, division, print_function
104103

105104
import six
106105

@@ -277,10 +276,7 @@ def _parse_commandline():
277276
'info', 'warning')
278277

279278
for arg in sys.argv[1:]:
280-
# cast to str because we are using unicode_literals,
281-
# and argv is always str
282-
283-
if arg.startswith(str('--verbose-')):
279+
if arg.startswith('--verbose-'):
284280
level_str = arg[10:]
285281
# If it doesn't match one of ours, then don't even
286282
# bother noting it, we are just a 3rd-party library
@@ -305,9 +301,7 @@ class Verbose(object):
305301
_commandLineVerbose = None
306302

307303
for arg in sys.argv[1:]:
308-
# cast to str because we are using unicode_literals,
309-
# and argv is always str
310-
if not arg.startswith(str('--verbose-')):
304+
if not arg.startswith('--verbose-'):
311305
continue
312306
level_str = arg[10:]
313307
# If it doesn't match one of ours, then don't even

lib/matplotlib/cbook/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66
it imports matplotlib only at runtime.
77
"""
88

9-
from __future__ import (absolute_import, division, print_function,
10-
unicode_literals)
9+
from __future__ import absolute_import, division, print_function
1110

1211
import six
1312
from six.moves import xrange, zip

lib/matplotlib/finance.py

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
This module is deprecated in 2.0 and has been moved to a module called
66
`mpl_finance`.
77
"""
8-
from __future__ import (absolute_import, division, print_function,
9-
unicode_literals)
8+
from __future__ import absolute_import, division, print_function
109

1110
import six
1211
from six.moves import xrange, zip
@@ -57,31 +56,31 @@ def md5(x):
5756

5857

5958
stock_dt_ohlc = np.dtype([
60-
(str('date'), object),
61-
(str('year'), np.int16),
62-
(str('month'), np.int8),
63-
(str('day'), np.int8),
64-
(str('d'), float), # mpl datenum
65-
(str('open'), float),
66-
(str('high'), float),
67-
(str('low'), float),
68-
(str('close'), float),
69-
(str('volume'), float),
70-
(str('aclose'), float)])
59+
('date', object),
60+
('year', np.int16),
61+
('month', np.int8),
62+
('day', np.int8),
63+
('d', float), # mpl datenum
64+
('open', float),
65+
('high', float),
66+
('low', float),
67+
('close', float),
68+
('volume', float),
69+
('aclose', float)])
7170

7271

7372
stock_dt_ochl = np.dtype(
74-
[(str('date'), object),
75-
(str('year'), np.int16),
76-
(str('month'), np.int8),
77-
(str('day'), np.int8),
78-
(str('d'), float), # mpl datenum
79-
(str('open'), float),
80-
(str('close'), float),
81-
(str('high'), float),
82-
(str('low'), float),
83-
(str('volume'), float),
84-
(str('aclose'), float)])
73+
[('date', object),
74+
('year', np.int16),
75+
('month', np.int8),
76+
('day', np.int8),
77+
('d', float), # mpl datenum
78+
('open', float),
79+
('close', float),
80+
('high', float),
81+
('low', float),
82+
('volume', float),
83+
('aclose', float)])
8584

8685

8786
def parse_yahoo_historical_ochl(fh, adjusted=True, asobject=False):

lib/matplotlib/font_manager.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@
1919
platforms, so if a font is installed, it is much more likely to be
2020
found.
2121
"""
22-
from __future__ import (absolute_import, division, print_function,
23-
unicode_literals)
22+
from __future__ import absolute_import, division, print_function
2423

2524
import six
2625
from six.moves import cPickle as pickle

lib/matplotlib/rcsetup.py

Lines changed: 43 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@
1313
parameter set listed here should also be visited to the
1414
:file:`matplotlibrc.template` in matplotlib's root source directory.
1515
"""
16-
from __future__ import (absolute_import, division, print_function,
17-
unicode_literals)
16+
from __future__ import absolute_import, division, print_function
1817

1918
import six
2019

@@ -97,11 +96,10 @@ def f(s):
9796
else:
9897
raise ValueError("{!r} must be of type: string or non-dictionary "
9998
"iterable".format(s))
100-
# Cast `str` to keep Py2 happy despite `unicode_literals`.
10199
try:
102-
f.__name__ = str("{}list".format(scalar_validator.__name__))
100+
f.__name__ = "{}list".format(scalar_validator.__name__)
103101
except AttributeError: # class instance.
104-
f.__name__ = str("{}List".format(type(scalar_validator).__name__))
102+
f.__name__ = "{}List".format(type(scalar_validator).__name__)
105103
f.__doc__ = scalar_validator.__doc__
106104
return f
107105

@@ -185,7 +183,7 @@ def validate_string_or_None(s):
185183
if s is None:
186184
return None
187185
try:
188-
return six.text_type(s)
186+
return validate_string(s)
189187
except ValueError:
190188
raise ValueError('Could not convert "%s" to string' % s)
191189

@@ -409,7 +407,15 @@ def deprecate_axes_colorcycle(value):
409407
validate_colorlist = _listify_validator(validate_color, allow_stringlist=True)
410408
validate_colorlist.__doc__ = 'return a list of colorspecs'
411409

412-
validate_stringlist = _listify_validator(six.text_type)
410+
def validate_string(s):
411+
if isinstance(s, str): # Always leave str as str
412+
return s
413+
elif isinstance(s, six.text_type):
414+
return s
415+
else:
416+
return str(s)
417+
418+
validate_stringlist = _listify_validator(str)
413419
validate_stringlist.__doc__ = 'return a list'
414420

415421
validate_orientation = ValidateInStrings(
@@ -483,7 +489,7 @@ def validate_whiskers(s):
483489
def update_savefig_format(value):
484490
# The old savefig.extension could also have a value of "auto", but
485491
# the new savefig.format does not. We need to fix this here.
486-
value = six.text_type(value)
492+
value = validate_string(value)
487493
if value == 'auto':
488494
value = 'png'
489495
return value
@@ -962,17 +968,17 @@ def _validate_linestyle(ls):
962968
'datapath': [None, validate_path_exists], # handled by
963969
# _get_data_path_cached
964970
'interactive': [False, validate_bool],
965-
'timezone': ['UTC', six.text_type],
971+
'timezone': ['UTC', validate_string],
966972

967973
# the verbosity setting
968974
'verbose.level': ['silent', validate_verbose],
969-
'verbose.fileo': ['sys.stdout', six.text_type],
975+
'verbose.fileo': ['sys.stdout', validate_string],
970976

971977
# line props
972978
'lines.linewidth': [1.5, validate_float], # line width in points
973979
'lines.linestyle': ['-', _validate_linestyle], # solid line
974980
'lines.color': ['C0', validate_color], # first color in color cycle
975-
'lines.marker': ['None', six.text_type], # marker name
981+
'lines.marker': ['None', validate_string], # marker name
976982
'lines.markeredgewidth': [1.0, validate_float],
977983
'lines.markersize': [6, validate_float], # markersize, in points
978984
'lines.antialiased': [True, validate_bool], # antialiased (no jaggies)
@@ -1016,7 +1022,7 @@ def _validate_linestyle(ls):
10161022
'boxplot.meanline': [False, validate_bool],
10171023

10181024
'boxplot.flierprops.color': ['k', validate_color],
1019-
'boxplot.flierprops.marker': ['o', six.text_type],
1025+
'boxplot.flierprops.marker': ['o', validate_string],
10201026
'boxplot.flierprops.markerfacecolor': ['none', validate_color_or_auto],
10211027
'boxplot.flierprops.markeredgecolor': ['k', validate_color],
10221028
'boxplot.flierprops.markersize': [6, validate_float],
@@ -1040,7 +1046,7 @@ def _validate_linestyle(ls):
10401046
'boxplot.medianprops.linestyle': ['-', _validate_linestyle],
10411047

10421048
'boxplot.meanprops.color': ['C2', validate_color],
1043-
'boxplot.meanprops.marker': ['^', six.text_type],
1049+
'boxplot.meanprops.marker': ['^', validate_string],
10441050
'boxplot.meanprops.markerfacecolor': ['C2', validate_color],
10451051
'boxplot.meanprops.markeredgecolor': ['C2', validate_color],
10461052
'boxplot.meanprops.markersize': [6, validate_float],
@@ -1049,10 +1055,10 @@ def _validate_linestyle(ls):
10491055

10501056
## font props
10511057
'font.family': [['sans-serif'], validate_stringlist], # used by text object
1052-
'font.style': ['normal', six.text_type],
1053-
'font.variant': ['normal', six.text_type],
1054-
'font.stretch': ['normal', six.text_type],
1055-
'font.weight': ['normal', six.text_type],
1058+
'font.style': ['normal', validate_string],
1059+
'font.variant': ['normal', validate_string],
1060+
'font.stretch': ['normal', validate_string],
1061+
'font.weight': ['normal', validate_string],
10561062
'font.size': [10, validate_float], # Base font size in points
10571063
'font.serif': [['DejaVu Serif', 'Bitstream Vera Serif',
10581064
'Computer Modern Roman',
@@ -1100,10 +1106,10 @@ def _validate_linestyle(ls):
11001106
'mathtext.fallback_to_cm': [True, validate_bool],
11011107

11021108
'image.aspect': ['equal', validate_aspect], # equal, auto, a number
1103-
'image.interpolation': ['nearest', six.text_type],
1104-
'image.cmap': ['viridis', six.text_type], # one of gray, jet, etc
1109+
'image.interpolation': ['nearest', validate_string],
1110+
'image.cmap': ['viridis', validate_string], # one of gray, jet, etc
11051111
'image.lut': [256, validate_int], # lookup table
1106-
'image.origin': ['upper', six.text_type], # lookup table
1112+
'image.origin': ['upper', validate_string], # lookup table
11071113
'image.resample': [True, validate_bool],
11081114
# Specify whether vector graphics backends will combine all images on a
11091115
# set of axes into a single composite image
@@ -1130,7 +1136,7 @@ def _validate_linestyle(ls):
11301136

11311137
'axes.titlesize': ['large', validate_fontsize], # fontsize of the
11321138
# axes title
1133-
'axes.titleweight': ['normal', six.text_type], # font weight of axes title
1139+
'axes.titleweight': ['normal', validate_string], # font weight of axes title
11341140
'axes.titlepad': [6.0, validate_float], # pad from axes top to title in points
11351141
'axes.grid': [False, validate_bool], # display grid or not
11361142
'axes.grid.which': ['major', validate_axis_locator], # set wether the gid are by
@@ -1142,7 +1148,7 @@ def _validate_linestyle(ls):
11421148
'axes.labelsize': ['medium', validate_fontsize], # fontsize of the
11431149
# x any y labels
11441150
'axes.labelpad': [4.0, validate_float], # space between label and axis
1145-
'axes.labelweight': ['normal', six.text_type], # fontsize of the x any y labels
1151+
'axes.labelweight': ['normal', validate_string], # fontsize of the x any y labels
11461152
'axes.labelcolor': ['k', validate_color], # color of axis label
11471153
'axes.formatter.limits': [[-7, 7], validate_nseq_int(2)],
11481154
# use scientific notation if log10
@@ -1187,16 +1193,16 @@ def _validate_linestyle(ls):
11871193
'axes3d.grid': [True, validate_bool], # display 3d grid
11881194

11891195
# scatter props
1190-
'scatter.marker': ['o', six.text_type],
1196+
'scatter.marker': ['o', validate_string],
11911197

11921198
# TODO validate that these are valid datetime format strings
1193-
'date.autoformatter.year': ['%Y', six.text_type],
1194-
'date.autoformatter.month': ['%Y-%m', six.text_type],
1195-
'date.autoformatter.day': ['%Y-%m-%d', six.text_type],
1196-
'date.autoformatter.hour': ['%m-%d %H', six.text_type],
1197-
'date.autoformatter.minute': ['%d %H:%M', six.text_type],
1198-
'date.autoformatter.second': ['%H:%M:%S', six.text_type],
1199-
'date.autoformatter.microsecond': ['%M:%S.%f', six.text_type],
1199+
'date.autoformatter.year': ['%Y', validate_string],
1200+
'date.autoformatter.month': ['%Y-%m', validate_string],
1201+
'date.autoformatter.day': ['%Y-%m-%d', validate_string],
1202+
'date.autoformatter.hour': ['%m-%d %H', validate_string],
1203+
'date.autoformatter.minute': ['%d %H:%M', validate_string],
1204+
'date.autoformatter.second': ['%H:%M:%S', validate_string],
1205+
'date.autoformatter.microsecond': ['%M:%S.%f', validate_string],
12001206

12011207
#legend properties
12021208
'legend.fancybox': [True, validate_bool],
@@ -1249,7 +1255,7 @@ def _validate_linestyle(ls):
12491255

12501256
# fontsize of the xtick labels
12511257
'xtick.labelsize': ['medium', validate_fontsize],
1252-
'xtick.direction': ['out', six.text_type], # direction of xticks
1258+
'xtick.direction': ['out', validate_string], # direction of xticks
12531259
'xtick.alignment': ["center", _validate_alignment],
12541260

12551261
'ytick.left': [True, validate_bool], # draw ticks on the left side
@@ -1269,7 +1275,7 @@ def _validate_linestyle(ls):
12691275

12701276
# fontsize of the ytick labels
12711277
'ytick.labelsize': ['medium', validate_fontsize],
1272-
'ytick.direction': ['out', six.text_type], # direction of yticks
1278+
'ytick.direction': ['out', validate_string], # direction of yticks
12731279
'ytick.alignment': ["center_baseline", _validate_alignment],
12741280

12751281

@@ -1282,7 +1288,7 @@ def _validate_linestyle(ls):
12821288
## figure props
12831289
# figure title
12841290
'figure.titlesize': ['large', validate_fontsize],
1285-
'figure.titleweight': ['normal', six.text_type],
1291+
'figure.titleweight': ['normal', validate_string],
12861292

12871293
# figure size in inches: width by height
12881294
'figure.figsize': [[6.4, 4.8], validate_nseq_float(2)],
@@ -1320,7 +1326,7 @@ def _validate_linestyle(ls):
13201326
'savefig.bbox': ['standard', validate_bbox],
13211327
'savefig.pad_inches': [0.1, validate_float],
13221328
# default directory in savefig dialog box
1323-
'savefig.directory': ['~', six.text_type],
1329+
'savefig.directory': ['~', validate_string],
13241330
'savefig.transparent': [False, validate_bool],
13251331

13261332
# Maintain shell focus for TkAgg
@@ -1361,7 +1367,7 @@ def _validate_linestyle(ls):
13611367
# set this when you want to generate hardcopy docstring
13621368
'docstring.hardcopy': [False, validate_bool],
13631369
# where plugin directory is locate
1364-
'plugins.directory': ['.matplotlib_plugins', six.text_type],
1370+
'plugins.directory': ['.matplotlib_plugins', validate_string],
13651371

13661372
'path.simplify': [True, validate_bool],
13671373
'path.simplify_threshold': [1.0 / 9.0, ValidateInterval(0.0, 1.0)],
@@ -1387,15 +1393,15 @@ def _validate_linestyle(ls):
13871393
'keymap.all_axes': [['a'], validate_stringlist],
13881394

13891395
# sample data
1390-
'examples.directory': ['', six.text_type],
1396+
'examples.directory': ['', validate_string],
13911397

13921398
# Animation settings
13931399
'animation.html': ['none', validate_movie_html_fmt],
13941400
# Limit, in MB, of size of base64 encoded animation in HTML
13951401
# (i.e. IPython notebook)
13961402
'animation.embed_limit': [20, validate_float],
13971403
'animation.writer': ['ffmpeg', validate_movie_writer],
1398-
'animation.codec': ['h264', six.text_type],
1404+
'animation.codec': ['h264', validate_string],
13991405
'animation.bitrate': [-1, validate_int],
14001406
# Controls image format when frames are written to disk
14011407
'animation.frame_format': ['png', validate_movie_frame_fmt],

lib/matplotlib/style/core.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
from __future__ import (absolute_import, division, print_function,
2-
unicode_literals)
1+
from __future__ import absolute_import, division, print_function
32

43
import six
54

lib/matplotlib/testing/compare.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
Provides a collection of utilities for comparing (image) results.
33
44
"""
5-
from __future__ import (absolute_import, division, print_function,
6-
unicode_literals)
5+
from __future__ import absolute_import, division, print_function
76

87
import six
98

lib/matplotlib/testing/decorators.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
from __future__ import (absolute_import, division, print_function,
2-
unicode_literals)
1+
from __future__ import absolute_import, division, print_function
32

43
import six
54

lib/matplotlib/tests/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
from __future__ import (absolute_import, division, print_function,
2-
unicode_literals)
1+
from __future__ import absolute_import, division, print_function
32

43
import six
54

lib/matplotlib/tests/conftest.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
from __future__ import (absolute_import, division, print_function,
2-
unicode_literals)
1+
from __future__ import absolute_import, division, print_function
32

43
from matplotlib.testing.conftest import (mpl_test_settings,
54
mpl_image_comparison_parameters,

0 commit comments

Comments
 (0)