Skip to content

Commit

Permalink
More Python 3 fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
benmwebb committed Dec 2, 2017
1 parent 867f999 commit f926b4c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
21 changes: 11 additions & 10 deletions tools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
import os.path
import re
import sys
import subst
import c_coverage
import sizeof_check
from . import subst
from . import c_coverage
from . import sizeof_check
from SCons.Script import *

__all__ = ["add_common_variables", "MyEnvironment", "get_pyext_environment",
Expand All @@ -25,7 +25,8 @@
import subprocess
def MyPopen(cmd):
return subprocess.Popen(cmd, shell=True, stdin=subprocess.PIPE,
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout=subprocess.PIPE, stderr=subprocess.PIPE,
universal_newlines=True)
except ImportError:
class MyPopen(object):
def __init__(self, cmd):
Expand Down Expand Up @@ -132,7 +133,7 @@ def check_pkgconfig(context, pkgconfig_name, human_name, env_key):
try:
flags = context.env.ParseFlags('!pkg-config --cflags --libs ' \
+ pkgconfig_name)
except OSError, detail:
except OSError as detail:
context.Result("failed: %s" % str(detail))
return False
context.env[env_key] = flags
Expand All @@ -159,14 +160,14 @@ def check_modeller_python(context):
context.Message("Checking for MODELLER in Python path...")
try:
import modeller
except ImportError, e:
except ImportError as e:
context.Result("not found (specify installation path with 'modeller' "
"scons option): %s" % str(e))
return False
try:
exetype = modeller.info.exe_type
bindir = modeller.info.bindir
except AttributeError, e:
except AttributeError as e:
context.Result("'import modeller' succeeded, but the package does "
"not appear to be MODELLER; perhaps a 'modeller.py' "
"file in the current directory?")
Expand Down Expand Up @@ -240,7 +241,7 @@ def CheckModeller(context):
moddir = "%s/bin" % modeller
try:
files = os.listdir(moddir)
except OSError, e:
except OSError as e:
context.Result("could not find MODELLER directory %s: %s" % (moddir, e))
return False
files.sort()
Expand All @@ -255,7 +256,7 @@ def CheckModeller(context):
p = MyPopen(modbin + " -")
print("print 'EXE type: ', info.exe_type", file=p.stdin)
p.stdin.close()
except IOError, e:
except IOError as e:
context.Result("could not run MODELLER script %s: %s" % (modbin, e))
return False
err = p.stderr.read()
Expand Down Expand Up @@ -368,7 +369,7 @@ def MyEnvironment(variables=None, require_modeller=True, *args, **kw):
# Find locally-installed libraries in /usr/local (e.g. for SWIG)
env['ENV']['LD_LIBRARY_PATH'] = '/usr/local/lib'
# Make Modeller exetype variable available:
if os.environ.has_key('EXECUTABLE_TYPESVN'):
if 'EXECUTABLE_TYPESVN' in os.environ:
env['ENV']['EXECUTABLE_TYPESVN'] = os.environ['EXECUTABLE_TYPESVN']
# Set empty variables in case checks fail or are not run (e.g. clean)
env['MODELLER_MODPY'] = ''
Expand Down
3 changes: 2 additions & 1 deletion tools/sphinx.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Simple Sphinx tool and builder.

from __future__ import print_function
import os
from SCons.Script import *

Expand All @@ -12,7 +13,7 @@ def _action_sphinx(target, source, env):
sourcedir, outdir)
ret = env.Execute(app)
if not ret:
print "Build finished. The HTML pages are in " + outdir
print("Build finished. The HTML pages are in " + outdir)
return ret

def generate(env):
Expand Down
5 changes: 5 additions & 0 deletions tools/swig.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
"""

from __future__ import print_function

#
# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 The SCons Foundation
#
Expand Down Expand Up @@ -38,6 +40,7 @@

import os.path
import re
import sys

import SCons.Action
import SCons.Defaults
Expand All @@ -62,6 +65,8 @@ def _get_swig_version(env):
out = pipe.stdout.read()
else:
out = os.popen(env['SWIG'] + ' -version').read()
if sys.version_info[0] >= 3 and isinstance(out, bytes):
out = out.decode()
match = re.search(r'SWIG Version\s+(\S+)\s*$', out, re.MULTILINE)
if match:
return match.group(1)
Expand Down

0 comments on commit f926b4c

Please sign in to comment.