Skip to content

Commit

Permalink
Use six instead of 2to3
Browse files Browse the repository at this point in the history
  • Loading branch information
mdboom committed Sep 3, 2013
1 parent d0a0100 commit f4adec7
Show file tree
Hide file tree
Showing 227 changed files with 2,545 additions and 1,670 deletions.
4 changes: 4 additions & 0 deletions boilerplate.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
# For some later history, see
# http://thread.gmane.org/gmane.comp.python.matplotlib.devel/7068

from __future__ import absolute_import, division, print_function, unicode_literals

import six

import os
import inspect
import random
Expand Down
4 changes: 3 additions & 1 deletion doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
'sphinxext.github',
'numpydoc']


try:
import numpydoc
except ImportError:
Expand All @@ -53,6 +52,9 @@
# The suffix of source filenames.
source_suffix = '.rst'

# This is the default encoding, but it doesn't hurt to be explicit
source_encoding = "utf-8"

# The master toctree document.
master_doc = 'contents'

Expand Down
15 changes: 9 additions & 6 deletions doc/users/plotting/examples/pgf_preamble.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import, division, print_function, unicode_literals

import six

import matplotlib as mpl
mpl.use("pgf")
Expand All @@ -7,9 +10,9 @@
"text.usetex": True, # use inline math for ticks
"pgf.rcfonts": False, # don't setup fonts from rc parameters
"pgf.preamble": [
r"\usepackage{units}", # load additional packages
r"\usepackage{metalogo}",
r"\usepackage{unicode-math}", # unicode math setup
"\\usepackage{units}", # load additional packages
"\\usepackage{metalogo}",
"\\usepackage{unicode-math}", # unicode math setup
r"\setmathfont{xits-math.otf}",
r"\setmainfont{DejaVu Serif}", # serif font via preamble
]
Expand All @@ -19,9 +22,9 @@
import matplotlib.pyplot as plt
plt.figure(figsize=(4.5,2.5))
plt.plot(range(5))
plt.xlabel(u"unicode text: я, ψ, €, ü, \\unitfrac[10]{°}{µm}")
plt.ylabel(u"\\XeLaTeX")
plt.legend([u"unicode math: $λ=∑_i^∞ μ_i^2$"])
plt.xlabel("unicode text: я, ψ, €, ü, \\unitfrac[10]{°}{µm}")
plt.ylabel("\\XeLaTeX")
plt.legend(["unicode math: $λ=∑_i^∞ μ_i^2$"])
plt.tight_layout(.5)

plt.savefig("pgf_preamble.pdf")
Expand Down
46 changes: 18 additions & 28 deletions lib/matplotlib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,9 @@
to MATLAB®, a registered trademark of The MathWorks, Inc.
"""
from __future__ import print_function, absolute_import
from __future__ import absolute_import, division, print_function, unicode_literals

import six
import sys
import distutils.version

Expand Down Expand Up @@ -166,17 +167,6 @@ def _forward_ilshift(self, other):

import sys, os, tempfile

if sys.version_info[0] >= 3:
def ascii(s): return bytes(s, 'ascii')

def byte2str(b): return b.decode('ascii')

else:
ascii = str

def byte2str(b): return b


from matplotlib.rcsetup import (defaultParams,
validate_backend,
validate_toolbar)
Expand Down Expand Up @@ -224,7 +214,7 @@ def _is_writable_dir(p):
try:
t = tempfile.TemporaryFile(dir=p)
try:
t.write(ascii('1'))
t.write(b'1')
finally:
t.close()
except OSError:
Expand Down Expand Up @@ -304,7 +294,7 @@ def wrap(self, fmt, func, level='helpful', always=True):
if always is True, the report will occur on every function
call; otherwise only on the first time the function is called
"""
assert callable(func)
assert six.callable(func)
def wrapper(*args, **kwargs):
ret = func(*args, **kwargs)

Expand All @@ -330,7 +320,7 @@ def checkdep_dvipng():
s = subprocess.Popen(['dvipng','-version'], stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
line = s.stdout.readlines()[1]
v = byte2str(line.split()[-1])
v = line.split()[-1].decode('ascii')
return v
except (IndexError, ValueError, OSError):
return None
Expand All @@ -347,7 +337,7 @@ def checkdep_ghostscript():
stderr=subprocess.PIPE)
stdout, stderr = s.communicate()
if s.returncode == 0:
v = byte2str(stdout[:-1])
v = stdout[:-1]
return gs_exec, v

return None, None
Expand All @@ -358,7 +348,7 @@ def checkdep_tex():
try:
s = subprocess.Popen(['tex','-version'], stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
line = byte2str(s.stdout.readlines()[0])
line = s.stdout.readlines()[0].decode('ascii')
pattern = '3\.1\d+'
match = re.search(pattern, line)
v = match.group(0)
Expand All @@ -372,7 +362,7 @@ def checkdep_pdftops():
stderr=subprocess.PIPE)
for line in s.stderr:
if b'version' in line:
v = byte2str(line.split()[-1])
v = line.split()[-1].decode('ascii')
return v
except (IndexError, ValueError, UnboundLocalError, OSError):
return None
Expand All @@ -383,7 +373,7 @@ def checkdep_inkscape():
stderr=subprocess.PIPE)
for line in s.stdout:
if b'Inkscape' in line:
v = byte2str(line.split()[1])
v = line.split()[1].decode('ascii')
break
return v
except (IndexError, ValueError, UnboundLocalError, OSError):
Expand All @@ -395,7 +385,7 @@ def checkdep_xmllint():
stderr=subprocess.PIPE)
for line in s.stderr:
if b'version' in line:
v = byte2str(line.split()[-1])
v = line.split()[-1].decode('ascii')
break
return v
except (IndexError, ValueError, UnboundLocalError, OSError):
Expand Down Expand Up @@ -771,7 +761,7 @@ class RcParams(dict):
"""

validate = dict((key, converter) for key, (default, converter) in
defaultParams.iteritems())
six.iteritems(defaultParams))
msg_depr = "%s is deprecated and replaced with %s; please use the latter."
msg_depr_ignore = "%s is deprecated and ignored. Use %s"

Expand Down Expand Up @@ -856,7 +846,7 @@ def rc_params(fail_on_error=False):
# this should never happen, default in mpl-data should always be found
message = 'could not find rc file; returning defaults'
ret = RcParams([(key, default) for key, (default, _) in \
defaultParams.iteritems() ])
six.iteritems(defaultParams)])
warnings.warn(message)
return ret

Expand Down Expand Up @@ -888,7 +878,7 @@ def rc_params_from_file(fname, fail_on_error=False):
rc_temp[key] = (val, line, cnt)

ret = RcParams([(key, default) for key, (default, _) in \
defaultParams.iteritems()])
six.iteritems(defaultParams)])

for key in ('verbose.level', 'verbose.fileo'):
if key in rc_temp:
Expand All @@ -904,7 +894,7 @@ def rc_params_from_file(fname, fail_on_error=False):
verbose.set_level(ret['verbose.level'])
verbose.set_fileo(ret['verbose.fileo'])

for key, (val, line, cnt) in rc_temp.iteritems():
for key, (val, line, cnt) in six.iteritems(rc_temp):
if key in defaultParams:
if fail_on_error:
ret[key] = val # try to convert to proper type or raise
Expand Down Expand Up @@ -960,8 +950,8 @@ def rc_params_from_file(fname, fail_on_error=False):

rcParamsOrig = rcParams.copy()

rcParamsDefault = RcParams([ (key, default) for key, (default, converter) in \
defaultParams.iteritems() ])
rcParamsDefault = RcParams([(key, default) for key, (default, converter) in \
six.iteritems(defaultParams)])

rcParams['ps.usedistiller'] = checkdep_ps_distiller(rcParams['ps.usedistiller'])
rcParams['text.usetex'] = checkdep_usetex(rcParams['text.usetex'])
Expand Down Expand Up @@ -1033,7 +1023,7 @@ def rc(group, **kwargs):
if is_string_like(group):
group = (group,)
for g in group:
for k,v in kwargs.iteritems():
for k, v in six.iteritems(kwargs):
name = aliases.get(k) or k
key = '%s.%s' % (g, name)
try:
Expand Down Expand Up @@ -1289,4 +1279,4 @@ def test(verbosity=1):
verbose.report('verbose.level %s'%verbose.level)
verbose.report('interactive is %s'%rcParams['interactive'])
verbose.report('platform is %s'%sys.platform)
verbose.report('loaded modules: %s'%sys.modules.iterkeys(), 'debug')
verbose.report('loaded modules: %s'%six.iterkeys(sys.modules), 'debug')
2 changes: 1 addition & 1 deletion lib/matplotlib/_cm.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
Documentation for each is in pyplot.colormaps()
"""

from __future__ import print_function, division
from __future__ import absolute_import, division, print_function, unicode_literals
import numpy as np

_binary_data = {
Expand Down
30 changes: 16 additions & 14 deletions lib/matplotlib/_mathtext_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
"""
# this dict maps symbol names to fontnames, glyphindex. To get the
# glyph index from the character code, you have to use get_charmap
from __future__ import print_function
from __future__ import absolute_import, division, print_function, unicode_literals

import six

"""
from matplotlib.ft2font import FT2Font
Expand Down Expand Up @@ -88,7 +90,7 @@
r'\rho' : ('cmmi10', 39),
r'\sigma' : ('cmmi10', 21),
r'\tau' : ('cmmi10', 43),
r'\upsilon' : ('cmmi10', 25),
'\\upsilon' : ('cmmi10', 25),
r'\phi' : ('cmmi10', 42),
r'\chi' : ('cmmi10', 17),
r'\psi' : ('cmmi10', 31),
Expand Down Expand Up @@ -129,7 +131,7 @@
r'\Xi' : ('cmr10', 3),
r'\Pi' : ('cmr10', 17),
r'\Sigma' : ('cmr10', 10),
r'\Upsilon' : ('cmr10', 11),
'\\Upsilon' : ('cmr10', 11),
r'\Phi' : ('cmr10', 9),
r'\Psi' : ('cmr10', 15),
r'\Omega' : ('cmr10', 12),
Expand All @@ -149,15 +151,15 @@
r'\combiningdotabove' : ('cmr10', 26), # for \dot

r'\leftarrow' : ('cmsy10', 10),
r'\uparrow' : ('cmsy10', 25),
'\\uparrow' : ('cmsy10', 25),
r'\downarrow' : ('cmsy10', 28),
r'\leftrightarrow' : ('cmsy10', 24),
r'\nearrow' : ('cmsy10', 99),
r'\searrow' : ('cmsy10', 57),
r'\simeq' : ('cmsy10', 108),
r'\Leftarrow' : ('cmsy10', 104),
r'\Rightarrow' : ('cmsy10', 112),
r'\Uparrow' : ('cmsy10', 60),
'\\Uparrow' : ('cmsy10', 60),
r'\Downarrow' : ('cmsy10', 68),
r'\Leftrightarrow' : ('cmsy10', 51),
r'\nwarrow' : ('cmsy10', 65),
Expand All @@ -180,7 +182,7 @@
r'\aleph' : ('cmsy10', 26),
r'\cup' : ('cmsy10', 6),
r'\cap' : ('cmsy10', 19),
r'\uplus' : ('cmsy10', 58),
'\\uplus' : ('cmsy10', 58),
r'\wedge' : ('cmsy10', 43),
r'\vee' : ('cmsy10', 96),
r'\vdash' : ('cmsy10', 109),
Expand All @@ -194,8 +196,8 @@
r'\mid' : ('cmsy10', 47),
r'\vert' : ('cmsy10', 47),
r'\Vert' : ('cmsy10', 44),
r'\updownarrow' : ('cmsy10', 94),
r'\Updownarrow' : ('cmsy10', 53),
'\\updownarrow' : ('cmsy10', 94),
'\\Updownarrow' : ('cmsy10', 53),
r'\backslash' : ('cmsy10', 126),
r'\wr' : ('cmsy10', 101),
r'\nabla' : ('cmsy10', 110),
Expand Down Expand Up @@ -296,7 +298,7 @@
r'\rho' : ('psyr', 114),
r'\sigma' : ('psyr', 115),
r'\tau' : ('psyr', 116),
r'\upsilon' : ('psyr', 117),
'\\upsilon' : ('psyr', 117),
r'\varpi' : ('psyr', 118),
r'\omega' : ('psyr', 119),
r'\xi' : ('psyr', 120),
Expand All @@ -311,7 +313,7 @@
r'\spadesuit' : ('psyr', 170),
r'\leftrightarrow' : ('psyr', 171),
r'\leftarrow' : ('psyr', 172),
r'\uparrow' : ('psyr', 173),
'\\uparrow' : ('psyr', 173),
r'\rightarrow' : ('psyr', 174),
r'\downarrow' : ('psyr', 175),
r'\pm' : ('psyr', 176),
Expand Down Expand Up @@ -350,12 +352,12 @@
r'\surd' : ('psyr', 214),
r'\__sqrt__' : ('psyr', 214),
r'\cdot' : ('psyr', 215),
r'\urcorner' : ('psyr', 216),
'\\urcorner' : ('psyr', 216),
r'\vee' : ('psyr', 217),
r'\wedge' : ('psyr', 218),
r'\Leftrightarrow' : ('psyr', 219),
r'\Leftarrow' : ('psyr', 220),
r'\Uparrow' : ('psyr', 221),
'\\Uparrow' : ('psyr', 221),
r'\Rightarrow' : ('psyr', 222),
r'\Downarrow' : ('psyr', 223),
r'\Diamond' : ('psyr', 224),
Expand All @@ -378,7 +380,7 @@
r'\slash' : ('psyr', 0o57),
r'\Lamda' : ('psyr', 0o114),
r'\neg' : ('psyr', 0o330),
r'\Upsilon' : ('psyr', 0o241),
'\\Upsilon' : ('psyr', 0o241),
r'\rightbrace' : ('psyr', 0o175),
r'\rfloor' : ('psyr', 0o373),
r'\lambda' : ('psyr', 0o154),
Expand Down Expand Up @@ -1764,7 +1766,7 @@
'uni044B' : 1099
}

uni2type1 = dict(((v,k) for k,v in type12uni.iteritems()))
uni2type1 = dict(((v,k) for k,v in six.iteritems(type12uni)))

tex2uni = {
'widehat' : 0x0302,
Expand Down
13 changes: 6 additions & 7 deletions lib/matplotlib/_pylab_helpers.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
"""
Manage figures for pyplot interface.
"""
from __future__ import print_function
from __future__ import absolute_import, division, print_function, unicode_literals

import six

import sys, gc

Expand Down Expand Up @@ -72,7 +74,7 @@ def destroy(num):
def destroy_fig(fig):
"*fig* is a Figure instance"
num = None
for manager in Gcf.figs.itervalues():
for manager in six.itervalues(Gcf.figs):
if manager.canvas.figure == fig:
num = manager.num
break
Expand All @@ -81,7 +83,7 @@ def destroy_fig(fig):

@staticmethod
def destroy_all():
for manager in Gcf.figs.values():
for manager in list(Gcf.figs.values()):
manager.canvas.mpl_disconnect(manager._cidgcf)
manager.destroy()

Expand All @@ -101,7 +103,7 @@ def get_all_fig_managers():
"""
Return a list of figure managers.
"""
return Gcf.figs.values()
return list(Gcf.figs.values())

@staticmethod
def get_num_fig_managers():
Expand Down Expand Up @@ -133,6 +135,3 @@ def set_active(manager):


atexit.register(Gcf.destroy_all)



Loading

0 comments on commit f4adec7

Please sign in to comment.