|
From: <ry...@us...> - 2010-07-11 02:29:15
|
Revision: 8540
http://matplotlib.svn.sourceforge.net/matplotlib/?rev=8540&view=rev
Author: ryanmay
Date: 2010-07-11 02:29:08 +0000 (Sun, 11 Jul 2010)
Log Message:
-----------
Make setupext.py compatible with both Python 2 and 3.
Modified Paths:
--------------
trunk/matplotlib/setupext.py
Modified: trunk/matplotlib/setupext.py
===================================================================
--- trunk/matplotlib/setupext.py 2010-07-09 18:30:07 UTC (rev 8539)
+++ trunk/matplotlib/setupext.py 2010-07-11 02:29:08 UTC (rev 8540)
@@ -78,14 +78,22 @@
}
import sys, os, stat
-if sys.platform != 'win32':
- import commands
+
from textwrap import fill
from distutils.core import Extension
import glob
-import ConfigParser
-import cStringIO
+if sys.version_info[0] < 3:
+ import ConfigParser as configparser
+ from cStringIO import StringIO
+ if sys.platform != 'win32':
+ from commands import getstatusoutput
+else:
+ import configparser
+ from io import StringIO
+ if sys.platform != 'win32':
+ from subprocess import getstatusoutput
+
BUILT_PNG = False
BUILT_AGG = False
BUILT_FT2FONT = False
@@ -132,7 +140,7 @@
# Based on the contents of setup.cfg, determine the build options
if os.path.exists("setup.cfg"):
- config = ConfigParser.SafeConfigParser()
+ config = configparser.SafeConfigParser()
config.read("setup.cfg")
try: options['display_status'] = not config.getboolean("status", "suppress")
@@ -174,27 +182,27 @@
basedirlist = options['basedirlist'].split()
else:
basedirlist = basedir[sys.platform]
-print "basedirlist is:", basedirlist
+print("basedirlist is: %s" % basedirlist)
if options['display_status']:
def print_line(char='='):
- print char * 76
+ print(char * 76)
def print_status(package, status):
initial_indent = "%22s: " % package
indent = ' ' * 24
- print fill(str(status), width=76,
+ print(fill(str(status), width=76,
initial_indent=initial_indent,
- subsequent_indent=indent)
+ subsequent_indent=indent))
def print_message(message):
indent = ' ' * 24 + "* "
- print fill(str(message), width=76,
+ print(fill(str(message), width=76,
initial_indent=indent,
- subsequent_indent=indent)
+ subsequent_indent=indent))
def print_raw(section):
- print section
+ print(section)
else:
def print_line(*args, **kwargs):
pass
@@ -248,7 +256,7 @@
has_pkgconfig.cache = False
else:
#print 'environ', os.environ['PKG_CONFIG_PATH']
- status, output = commands.getstatusoutput("pkg-config --help")
+ status, output = getstatusoutput("pkg-config --help")
has_pkgconfig.cache = (status == 0)
return has_pkgconfig.cache
has_pkgconfig.cache = None
@@ -270,7 +278,7 @@
'-U': 'undef_macros'}
cmd = "%s %s %s" % (pkg_config_exec, flags, packages)
- status, output = commands.getstatusoutput(cmd)
+ status, output = getstatusoutput(cmd)
if status == 0:
for token in output.split():
attr = _flags.get(token[:2], None)
@@ -298,7 +306,7 @@
if not has_pkgconfig():
return default
- status, output = commands.getstatusoutput(
+ status, output = getstatusoutput(
"pkg-config %s --modversion" % (package))
if status == 0:
return output
@@ -466,7 +474,7 @@
def check_for_dvipng():
try:
stdin, stdout = run_child_process('dvipng -version')
- print_status("dvipng", stdout.readlines()[1].split()[-1])
+ print_status("dvipng", stdout.readlines()[1].decode().split()[-1])
return True
except (IndexError, ValueError):
print_status("dvipng", "no")
@@ -479,7 +487,7 @@
else:
command = 'gs --version'
stdin, stdout = run_child_process(command)
- print_status("ghostscript", stdout.read()[:-1])
+ print_status("ghostscript", stdout.read().decode()[:-1])
return True
except (IndexError, ValueError):
print_status("ghostscript", "no")
@@ -488,7 +496,7 @@
def check_for_latex():
try:
stdin, stdout = run_child_process('latex -version')
- line = stdout.readlines()[0]
+ line = stdout.readlines()[0].decode()
pattern = '(3\.1\d+)|(MiKTeX \d+.\d+)'
match = re.search(pattern, line)
print_status("latex", match.group(0))
@@ -501,6 +509,7 @@
try:
stdin, stdout = run_child_process('pdftops -v')
for line in stdout.readlines():
+ line = line.decode()
if 'version' in line:
print_status("pdftops", line.split()[-1])
return True
@@ -794,7 +803,6 @@
# Make sure you use the Tk version given by Tkinter.TkVersion
# or else you'll build for a wrong version of the Tcl
# interpreter (leading to nasty segfaults).
-
def check_for_tk():
gotit = False
explanation = None
@@ -814,9 +822,15 @@
module = Extension('test', [])
try:
explanation = add_tk_flags(module)
- except RuntimeError, e:
- explanation = str(e)
+ except RuntimeError:
+ # This deals with the change in exception handling syntax in
+ # python 3. If we only need to support >= 2.6, we can just use the
+ # commented out lines below.
+ exc_type,exc,tb = sys.exc_info()
+ explanation = str(exc)
gotit = False
+# except RuntimeError, e:
+# explanation = str(e)
else:
if not find_include_file(module.include_dirs, "tk.h"):
message = 'Tkinter present, but header files are not found. ' + \
@@ -910,23 +924,21 @@
# So, we push a "[default]" section to a copy of the
# file in a StringIO object.
try:
- tcl_vars_str = cStringIO.StringIO(
- "[default]\n" + open(tcl_config, "r").read())
- tk_vars_str = cStringIO.StringIO(
- "[default]\n" + open(tk_config, "r").read())
+ tcl_vars_str = StringIO("[default]\n" + open(tcl_config, "r").read())
+ tk_vars_str = StringIO("[default]\n" + open(tk_config, "r").read())
except IOError:
# if we can't read the file, that's ok, we'll try
# to guess instead
return None
tcl_vars_str.seek(0)
- tcl_vars = ConfigParser.RawConfigParser()
+ tcl_vars = configparser.RawConfigParser()
tk_vars_str.seek(0)
- tk_vars = ConfigParser.RawConfigParser()
+ tk_vars = configparser.RawConfigParser()
try:
tcl_vars.readfp(tcl_vars_str)
tk_vars.readfp(tk_vars_str)
- except ConfigParser.ParsingError:
+ except configparser.ParsingError:
# if we can't read the file, that's ok, we'll try
# to guess instead
return None
@@ -942,7 +954,7 @@
else:
# On RHEL4
tk_inc = tcl_inc
- except (ConfigParser.NoSectionError, ConfigParser.NoOptionError):
+ except (configparser.NoSectionError, configparser.NoOptionError):
return None
if not os.path.exists(os.path.join(tk_inc, 'tk.h')):
@@ -1043,8 +1055,8 @@
#
tk_include_dirs = [
join(F, fw + '.framework', H)
- for fw in 'Tcl', 'Tk'
- for H in 'Headers', 'Versions/Current/PrivateHeaders'
+ for fw in ('Tcl', 'Tk')
+ for H in ('Headers', 'Versions/Current/PrivateHeaders')
]
# For 8.4a2, the X11 headers are not included. Rather than include a
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|