Skip to content

Commit

Permalink
More miscellaneous print_function updates.
Browse files Browse the repository at this point in the history
  • Loading branch information
mdboom committed Mar 14, 2011
1 parent 97d7daf commit a32eb4e
Show file tree
Hide file tree
Showing 33 changed files with 116 additions and 74 deletions.
1 change: 1 addition & 0 deletions release/win32/data/setupwin.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import print_function
from distutils import cygwinccompiler

try:
Expand Down
1 change: 1 addition & 0 deletions release/win32/data/setupwinegg.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import print_function
from distutils import cygwinccompiler

try:
Expand Down
1 change: 1 addition & 0 deletions test/_buildbot_install.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""This script will install matplotlib to a virtual environment to
faciltate testing."""
from __future__ import print_function
import shutil, os, sys
from subprocess import Popen, PIPE, STDOUT
from optparse import OptionParser
Expand Down
1 change: 1 addition & 0 deletions test/_buildbot_test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""This script will test matplotlib in a virtual environment"""
from __future__ import print_function
import os, glob

from _buildbot_util import check_call
Expand Down
5 changes: 3 additions & 2 deletions test/_buildbot_test_postmortem.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
This is meant to be run from the mplroot directory."""

from __future__ import print_function
import os, shutil

roots = ['test_matplotlib','test_plots']
Expand Down Expand Up @@ -91,8 +92,8 @@ def path_split_all(fname):
continue
if not os.path.exists(expected_fname):
continue
print fname
print absdiff_fname
print(fname)
print(absdiff_fname)

teststr = os.path.splitext(fname)[0]
this_targetdir = os.path.join(target_dir,teststr)
Expand Down
1 change: 1 addition & 0 deletions test/_buildbot_util.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Module to help _buildbot_*.py scripts."""

from __future__ import print_function
import shutil, os, sys
from subprocess import Popen, PIPE, STDOUT

Expand Down
1 change: 1 addition & 0 deletions unit/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from __future__ import print_function
5 changes: 3 additions & 2 deletions unit/agg_memleak.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
And another broken test...
"""

from __future__ import print_function
import sys, time, os
from matplotlib.ft2font import FT2Font
from numpy.random import rand
Expand All @@ -11,7 +12,7 @@
def report_memory(i):
pid = os.getpid()
a2 = os.popen('ps -p %d -o rss,sz' % pid).readlines()
print i, ' ', a2[1],
print(i, ' ', a2[1], end='')
return int(a2[1].split()[0])

fname = '/usr/local/share/matplotlib/Vera.ttf'
Expand Down Expand Up @@ -52,7 +53,7 @@ def report_memory(i):
if i==1: start = val

end = val
print 'Average memory consumed per loop: %1.4f\n' % ((end-start)/float(N))
print('Average memory consumed per loop: %1.4f\n' % ((end-start)/float(N)))

# w/o text and w/o write_png: Average memory consumed per loop: 0.02
# w/o text and w/ write_png : Average memory consumed per loop: 0.3400
Expand Down
1 change: 1 addition & 0 deletions unit/auto_legend.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import print_function
from pylab import *
import sys

Expand Down
1 change: 1 addition & 0 deletions unit/cbook_unit.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import print_function
import unittest
from datetime import datetime

Expand Down
15 changes: 8 additions & 7 deletions unit/compare_backend_driver_results.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import print_function
import sys

def parse_results(filename):
Expand Down Expand Up @@ -33,9 +34,9 @@ def compare_results(results_a, results_b):
sections = results_a.keys()
sections.sort()
for section in results_a.keys():
print "backend %s" % section
print " %-40s %6s %6s %6s %6s" % ("test", "a", "b", "delta", "% diff")
print " " + '-' * 69
print("backend %s" % section)
print(" %-40s %6s %6s %6s %6s" % ("test", "a", "b", "delta", "% diff"))
print(" " + '-' * 69)
deltas = []
section_a = results_a[section]
section_b = results_b[section]
Expand All @@ -54,13 +55,13 @@ def compare_results(results_a, results_b):
for diff, delta, time_a, time_b, test in deltas:
if diff is None:
if time_a is None:
print " %-40s ??? % 6.3f ??? ???" % (test, time_b)
print(" %-40s ??? % 6.3f ??? ???" % (test, time_b))
else:
print " %-40s % 6.3f ??? ??? ???" % (test, time_a)
print(" %-40s % 6.3f ??? ??? ???" % (test, time_a))
else:
print " %-40s % 6.3f % 6.3f % 6.3f %6d%%" % (test, time_a, time_b, delta, diff * 100)
print(" %-40s % 6.3f % 6.3f % 6.3f %6d%%" % (test, time_a, time_b, delta, diff * 100))



if __name__ == '__main__':
results_a_filename = sys.argv[-2]
results_b_filename = sys.argv[-1]
Expand Down
7 changes: 4 additions & 3 deletions unit/dates_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Check to and form the epoch conversions for the various datetime
converters
"""
from __future__ import print_function
from matplotlib.dates import MxDatetimeConverter, PyDatetimeConverter,\
EpochConverter
import mx.DateTime
Expand All @@ -13,7 +14,7 @@

assert( dtc.from_epoch( dtc.epoch(dt1) ) == dt1 )
assert( dtc.from_epoch( dtc.epoch(dt2) ) == dt2 )
print 'passed mx tests'
print('passed mx tests')

import datetime
dt1 = datetime.datetime(2004, 03, 01) # before dst
Expand All @@ -22,7 +23,7 @@
dtc = PyDatetimeConverter()
assert( dtc.from_epoch( dtc.epoch(dt1) ) == dt1 )
assert( dtc.from_epoch( dtc.epoch(dt2) ) == dt2 )
print 'passed datetime tests'
print('passed datetime tests')

# epoch
dt1 = 12345334
Expand All @@ -31,4 +32,4 @@
dtc = EpochConverter()
assert( dtc.from_epoch( dtc.epoch(dt1) ) == dt1 )
assert( dtc.from_epoch( dtc.epoch(dt2) ) == dt2 )
print 'passed epoch tests'
print('passed epoch tests')
1 change: 1 addition & 0 deletions unit/ellipse_compare.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Compare the ellipse generated with arcs versus a polygonal approximation
"""
from __future__ import print_function
import numpy as npy
from matplotlib import patches
from pylab import figure, show
Expand Down
1 change: 1 addition & 0 deletions unit/ellipse_large.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# bound ellipses, it demonstrates how significant this error
# is to our plots.

from __future__ import print_function
import math
from pylab import *
from matplotlib.patches import Ellipse, Arc
Expand Down
5 changes: 3 additions & 2 deletions unit/ft2font_memleak.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
This appears to be obsolete as of 2009/02/24; a key import fails.
"""
from __future__ import print_function
import sys, time, os
from numpy.random import rand
from matplotlib.ft2font import FT2Font
Expand All @@ -11,7 +12,7 @@
def report_memory(i):
pid = os.getpid()
a2 = os.popen('ps -p %d -o rss,sz' % pid).readlines()
print i, ' ', a2[1],
print(i, ' ', a2[1], end='')
return int(a2[1].split()[0])

fname = '/usr/local/share/matplotlib/Vera.ttf'
Expand All @@ -32,6 +33,6 @@ def report_memory(i):
if i==1: start = val

end = val
print 'Average memory consumed per loop: %1.4f\n' % ((end-start)/float(N))
print('Average memory consumed per loop: %1.4f\n' % ((end-start)/float(N)))

# Average memory consumed per loop: 0.09
4 changes: 3 additions & 1 deletion unit/inside_poly_memleak.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
#!/usr/bin/env python

"""
Another broken test...
"""

from __future__ import print_function
import os, sys, time
import matplotlib.nxutils as nxutils
from numpy.random import rand

def report_memory(i):
pid = os.getpid()
a2 = os.popen('ps -p %d -o rss,sz' % pid).readlines()
print i, ' ', a2[1],
print(i, ' ', a2[1], end='')
return int(a2[1].split()[1])


Expand Down
3 changes: 2 additions & 1 deletion unit/inside_poly_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Broken.
"""

from __future__ import print_function
import os, sys, time

import matplotlib.nxutils as nxutils
Expand All @@ -24,7 +25,7 @@
points = rand(numpoints,2)
mask = nxutils.points_inside_poly(points, verts)
tnew = time.time() - t0
print numverts, numpoints, told, tnew, told/tnew
print(numverts, numpoints, told, tnew, told/tnew)



1 change: 1 addition & 0 deletions unit/legend_unit.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import print_function
from pylab import figure, show, nx

Ntests = 3
Expand Down
2 changes: 2 additions & 0 deletions unit/longs_test.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/usr/bin/env python
# try plotting very large numbers

from __future__ import print_function

from pylab import *
x = arange(1000) + 2**32

Expand Down
40 changes: 21 additions & 19 deletions unit/memleak_gui.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env python

'''
This illustrates a leak that occurs with any interactive backend.
Run with :
Expand All @@ -13,6 +14,7 @@
You may need to edit cbook.report_memory to support your platform
'''
from __future__ import print_function
import os, sys, time
import gc
from optparse import OptionParser
Expand Down Expand Up @@ -48,8 +50,8 @@
import pylab
import matplotlib.cbook as cbook

print '# columns are: iteration, OS memory (k), number of python objects'
print '#'
print('# columns are: iteration, OS memory (k), number of python objects')
print('#')
for i in range(indEnd+1):

fig = pylab.figure()
Expand All @@ -68,40 +70,40 @@
gc.collect()
end = val

print '# columns above are: iteration, OS memory (k), number of python objects'
print '#'
print '# uncollectable list:', gc.garbage
print '#'
print('# columns above are: iteration, OS memory (k), number of python objects')
print('#')
print('# uncollectable list:', gc.garbage)
print('#')

if i > indStart:
print '# Backend %(backend)s, toolbar %(toolbar)s' % matplotlib.rcParams
print('# Backend %(backend)s, toolbar %(toolbar)s' % matplotlib.rcParams)
backend = options.backend.lower()
if backend.startswith("gtk"):
import gtk
import gobject
print "# pygtk version: %s, gtk version: %s, pygobject version: %s, glib version: %s" % \
(gtk.pygtk_version, gtk.gtk_version,
gobject.pygobject_version, gobject.glib_version)
print("# pygtk version: %s, gtk version: %s, pygobject version: %s, glib version: %s" % \
(gtk.pygtk_version, gtk.gtk_version,
gobject.pygobject_version, gobject.glib_version))
elif backend.startswith("qt4"):
import PyQt4.pyqtconfig
print "# PyQt4 version: %s, Qt version %x" % \
print("# PyQt4 version: %s, Qt version %x" % \
(PyQt4.pyqtconfig.Configuration().pyqt_version_str,
PyQt4.pyqtconfig.Configuration().qt_version)
PyQt4.pyqtconfig.Configuration().qt_version))
elif backend.startswith("qt"):
import pyqtconfig
print "# pyqt version: %s, qt version: %x" % \
print("# pyqt version: %s, qt version: %x" % \
(pyqtconfig.Configuration().pyqt_version_str,
pyqtconfig.Configuration().qt_version)
pyqtconfig.Configuration().qt_version))
elif backend.startswith("wx"):
import wx
print "# wxPython version: %s" % wx.__version__
print("# wxPython version: %s" % wx.__version__)
elif backend.startswith("tk"):
import Tkinter
print "# Tkinter version: %s, Tk version: %s, Tcl version: %s" % (Tkinter.__version__, Tkinter.TkVersion, Tkinter.TclVersion)
print("# Tkinter version: %s, Tk version: %s, Tcl version: %s" % (Tkinter.__version__, Tkinter.TkVersion, Tkinter.TclVersion))

print '# Averaging over loops %d to %d' % (indStart, indEnd)
print '# Memory went from %dk to %dk' % (start, end)
print '# Average memory consumed per loop: %1.4fk bytes\n' % ((end-start)/float(indEnd-indStart))
print('# Averaging over loops %d to %d' % (indStart, indEnd))
print('# Memory went from %dk to %dk' % (start, end))
print('# Average memory consumed per loop: %1.4fk bytes\n' % ((end-start)/float(indEnd-indStart)))

if options.cycles:
cbook.print_cycles(gc.garbage)
6 changes: 4 additions & 2 deletions unit/memleak_hawaii3.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/usr/bin/env python

from __future__ import print_function

import os, sys, time, gc
import matplotlib
matplotlib.use('PDF')
Expand Down Expand Up @@ -43,9 +45,9 @@

gc.collect()
val = report_memory(i)
print i, val
print(i, val)
if i==indStart: start = val # wait a few cycles for memory usage to stabilize

end = val
print 'Average memory consumed per loop: %1.4fk bytes\n' % ((end-start)/float(indEnd-indStart))
print('Average memory consumed per loop: %1.4fk bytes\n' % ((end-start)/float(indEnd-indStart)))

3 changes: 2 additions & 1 deletion unit/memleak_nongui.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import print_function
import os,matplotlib
matplotlib.use('Agg')
from matplotlib.figure import Figure
Expand All @@ -7,7 +8,7 @@ def plot():
fig = Figure()
i = 0
while True:
print i,report_memory(i)
print(i, report_memory(i))
fig.clf()
ax = fig.add_axes([0.1,0.1,0.7,0.7])
ax.plot([1,2,3])
Expand Down
11 changes: 6 additions & 5 deletions unit/mlab_unit.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import print_function
import datetime, StringIO, unittest
import matplotlib.mlab as mlab
import numpy
Expand Down Expand Up @@ -40,19 +41,19 @@ def test_csv2rec_roundtrip(self):
mlab.rec2csv( ra, fh )
fh.seek(0)
if 0:
print 'CSV contents:','-'*40
print fh.read()
print '-'*40
print('CSV contents:','-'*40)
print(fh.read())
print('-'*40)
fh.seek(0)
ra2 = mlab.csv2rec(fh)
fh.close()
#print 'ra', ra
#print 'ra2', ra2
for name in ra.dtype.names:
if 0:
print name, repr(ra[name]), repr(ra2[name])
print(name, repr(ra[name]), repr(ra2[name]))
dt = ra.dtype[name]
print 'repr(dt.type)',repr(dt.type)
print('repr(dt.type)',repr(dt.type))
self.failUnless( numpy.all(ra[name] == ra2[name]) ) # should not fail with numpy 1.0.5

def test_csv2rec_masks(self):
Expand Down
1 change: 1 addition & 0 deletions unit/nose_tests.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import print_function
import numpy as np

import nose, nose.tools as nt
Expand Down
Loading

0 comments on commit a32eb4e

Please sign in to comment.