diff --git a/SConstruct b/SConstruct index 754b27f27..dae4b2d0d 100644 --- a/SConstruct +++ b/SConstruct @@ -37,11 +37,12 @@ Basic usage: 'scons doxygen' - Build the Doxygen documentation """ +from __future__ import print_function from buildutils import * if not COMMAND_LINE_TARGETS: # Print usage help - print __doc__ + print(__doc__) sys.exit(0) valid_commands = ('build','clean','install','uninstall', @@ -49,7 +50,7 @@ valid_commands = ('build','clean','install','uninstall', for command in COMMAND_LINE_TARGETS: if command not in valid_commands and not command.startswith('test'): - print 'ERROR: unrecognized command line target: %r' % command + print('ERROR: unrecognized command line target: %r' % command) sys.exit(0) extraEnvArgs = {} @@ -100,7 +101,7 @@ if 'clean' in COMMAND_LINE_TARGETS: if name.startswith('ctmethods.'): removeFile('interfaces/matlab/toolbox/' + name) - print 'Done removing output files.' + print('Done removing output files.') if COMMAND_LINE_TARGETS == ['clean']: # Just exit if there's nothing else to do @@ -112,7 +113,7 @@ if 'clean' in COMMAND_LINE_TARGETS: # *** Set system-dependent defaults for some options *** # ****************************************************** -print 'INFO: SCons is using the following Python interpreter:', sys.executable +print('INFO: SCons is using the following Python interpreter:', sys.executable) opts = Variables('cantera.conf') @@ -162,8 +163,8 @@ if os.name == 'nt': toolchain = ['default'] if pickCompilerEnv['msvc_version']: extraEnvArgs['MSVC_VERSION'] = pickCompilerEnv['msvc_version'] - print 'INFO: Compiling with MSVC', (pickCompilerEnv['msvc_version'] or - pickCompilerEnv['MSVC_VERSION']) + print('INFO: Compiling with MSVC', (pickCompilerEnv['msvc_version'] or + pickCompilerEnv['MSVC_VERSION'])) elif pickCompilerEnv['toolchain'] == 'mingw': toolchain = ['mingw', 'f90'] @@ -175,8 +176,8 @@ if os.name == 'nt': toolchain = ['intelc'] # note: untested extraEnvArgs['TARGET_ARCH'] = pickCompilerEnv['target_arch'] - print 'INFO: Compiling for architecture:', pickCompilerEnv['target_arch'] - print 'INFO: Compiling using the following toolchain(s):', repr(toolchain) + print('INFO: Compiling for architecture:', pickCompilerEnv['target_arch']) + print('INFO: Compiling using the following toolchain(s):', repr(toolchain)) else: toolchain = ['default'] @@ -205,7 +206,7 @@ if 'HOME' in os.environ: # Fix an issue with Unicode sneaking into the environment on Windows if os.name == 'nt': - for key,val in env['ENV'].iteritems(): + for key,val in env['ENV'].items(): env['ENV'][key] = str(val) if 'FRAMEWORKS' not in env: @@ -224,7 +225,7 @@ elif os.name == 'nt': defaults.boostIncDir = '' env['INSTALL_MANPAGES'] = False else: - print "Error: Unrecognized operating system '%s'" % os.name + print("Error: Unrecognized operating system '%s'" % os.name) sys.exit(1) compiler_options = [ @@ -286,7 +287,7 @@ elif 'clang' in env.subst('$CC'): env['pch_flags'] = ['-include-pch', 'src/pch/system.h.gch'] else: - print "WARNING: Unrecognized C compiler '%s'" % env['CC'] + print("WARNING: Unrecognized C compiler '%s'" % env['CC']) if env['OS'] in ('Windows', 'Darwin'): defaults.threadFlags = '' @@ -630,7 +631,7 @@ opts.Save('cantera.conf', env) if 'help' in COMMAND_LINE_TARGETS: ### Print help about configuration options and exit. - print """ + print(""" ************************************************** * Configuration options for building Cantera * ************************************************** @@ -649,10 +650,10 @@ running 'scons build'. The format of this file is: option2 = 'value2' ************************************************** -""" +""") for opt in opts.options: - print '\n'.join(formatOption(env, opt)) + print('\n'.join(formatOption(env, opt))) sys.exit(0) if 'doxygen' in COMMAND_LINE_TARGETS: @@ -665,7 +666,7 @@ valid_arguments = (set(opt[0] for opt in windows_compiler_options) | set(opt[0] for opt in config_options)) for arg in ARGUMENTS: if arg not in valid_arguments: - print 'Encountered unexpected command line argument: %r' % arg + print('Encountered unexpected command line argument: %r' % arg) sys.exit(1) # Require a StrictVersion-compatible version @@ -681,10 +682,10 @@ except OSError: env['git_commit'] = '' # Print values of all build options: -print "Configuration variables read from 'cantera.conf' and command line:" +print("Configuration variables read from 'cantera.conf' and command line:") for line in open('cantera.conf'): - print ' ', line.strip() -print + print(' ', line.strip()) +print() # ******************************************** # *** Configure system-specific properties *** @@ -703,10 +704,10 @@ elif env['env_vars']: else: env['ENV'][name] = os.environ[name] if env['VERBOSE']: - print 'Propagating environment variable {0}={1}'.format(name, env['ENV'][name]) + print('Propagating environment variable {0}={1}'.format(name, env['ENV'][name])) elif name not in defaults.env_vars.split(','): - print 'WARNING: failed to propagate environment variable', repr(name) - print ' Edit cantera.conf or the build command line to fix this.' + print('WARNING: failed to propagate environment variable', repr(name)) + print(' Edit cantera.conf or the build command line to fix this.') env['extra_inc_dirs'] = [d for d in env['extra_inc_dirs'].split(':') if d] env['extra_lib_dirs'] = [d for d in env['extra_lib_dirs'].split(':') if d] @@ -793,20 +794,20 @@ if env['coverage']: env.Append(LINKFLAGS=['-fprofile-arcs', '-ftest-coverage']) else: - print 'Error: coverage testing is only available with GCC.' + print('Error: coverage testing is only available with GCC.') exit(0) if env['toolchain'] == 'mingw': env.Append(LINKFLAGS=['-static-libgcc', '-static-libstdc++']) def config_error(message): - print 'ERROR:', message + print('ERROR:', message) if env['VERBOSE']: - print '*' * 25, 'Contents of config.log:', '*' * 25 - print open('config.log').read() - print '*' * 28, 'End of config.log', '*' * 28 + print('*' * 25, 'Contents of config.log:', '*' * 25) + print(open('config.log').read()) + print('*' * 28, 'End of config.log', '*' * 28) else: - print "See 'config.log' for details." + print("See 'config.log' for details.") sys.exit(1) # First, a sanity check: @@ -818,7 +819,7 @@ if not conf.CheckCXXHeader('cmath', '<>'): if env['system_fmt'] in ('y', 'default'): if conf.CheckCXXHeader('fmt/ostream.h', '""'): env['system_fmt'] = True - print """INFO: Using system installation of fmt library.""" + print("""INFO: Using system installation of fmt library.""") elif env['system_fmt'] == 'y': config_error('Expected system installation of fmt library, but it ' @@ -826,7 +827,7 @@ if env['system_fmt'] in ('y', 'default'): if env['system_fmt'] in ('n', 'default'): env['system_fmt'] = False - print """INFO: Using private installation of fmt library.""" + print("""INFO: Using private installation of fmt library.""") if not os.path.exists('ext/fmt/fmt/ostream.h'): if not os.path.exists('.git'): config_error('fmt is missing. Install source in ext/fmt.') @@ -909,7 +910,7 @@ env['HAS_LIBCPP'] = conf.CheckDeclaration('_LIBCPP_VERSION', '#include '], 'BOOST_LIB_VERSION') retcode, boost_lib_version = conf.TryRun(boost_version_source, '.cpp') env['BOOST_LIB_VERSION'] = boost_lib_version.strip() -print 'INFO: Found Boost version {0!r}'.format(env['BOOST_LIB_VERSION']) +print('INFO: Found Boost version {0!r}'.format(env['BOOST_LIB_VERSION'])) if not env['BOOST_LIB_VERSION']: config_error("Boost could not be found. Install Boost headers or set" " 'boost_inc_dir' to point to the boost headers.") @@ -970,9 +971,9 @@ if env['system_sundials'] == 'y': # Ignore the minor version, e.g. 2.4.x -> 2.4 env['sundials_version'] = '.'.join(sundials_version.split('.')[:2]) if env['sundials_version'] not in ('2.4','2.5','2.6','2.7'): - print """ERROR: Sundials version %r is not supported.""" % env['sundials_version'] + print("""ERROR: Sundials version %r is not supported.""" % env['sundials_version']) sys.exit(1) - print """INFO: Using system installation of Sundials version %s.""" % sundials_version + print("""INFO: Using system installation of Sundials version %s.""" % sundials_version) #Determine whether or not Sundials was built with BLAS/LAPACK if LooseVersion(env['sundials_version']) < LooseVersion('2.6'): @@ -991,10 +992,10 @@ if env['system_sundials'] == 'y': # In the case where a user is trying to link Cantera to an external BLAS/LAPACK # library, but Sundials was configured without this support, print a Warning. if not env['has_sundials_lapack'] and env['use_lapack']: - print ('WARNING: External BLAS/LAPACK has been specified for Cantera ' - 'but Sundials was built without this support.') + print('WARNING: External BLAS/LAPACK has been specified for Cantera ' + 'but Sundials was built without this support.') else: # env['system_sundials'] == 'n' - print """INFO: Using private installation of Sundials version 2.6.""" + print("""INFO: Using private installation of Sundials version 2.6.""") env['sundials_version'] = '2.6' env['has_sundials_lapack'] = int(env['use_lapack']) @@ -1012,11 +1013,11 @@ end program main if success and 'Hello, world!' in output: return True else: - print ("WARNING: Unable to use '%s' to compile the Fortran " - "interface. See config.log for details." % compiler) + print("WARNING: Unable to use '%s' to compile the Fortran " + "interface. See config.log for details." % compiler) return False elif expected: - print "ERROR: Couldn't find specified Fortran compiler: '%s'" % compiler + print("ERROR: Couldn't find specified Fortran compiler: '%s'" % compiler) sys.exit(1) return False @@ -1034,16 +1035,16 @@ if env['f90_interface'] in ('y','default'): foundF90 = check_fortran(compiler) if foundF90: - print "INFO: Using '%s' to build the Fortran 90 interface" % env['FORTRAN'] + print("INFO: Using '%s' to build the Fortran 90 interface" % env['FORTRAN']) env['f90_interface'] = 'y' else: if env['f90_interface'] == 'y': - print "ERROR: Couldn't find a suitable Fortran compiler to build the Fortran 90 interface." + print("ERROR: Couldn't find a suitable Fortran compiler to build the Fortran 90 interface.") sys.exit(1) else: env['f90_interface'] = 'n' - env['FORTRAN'] = '' - print "INFO: Skipping compilation of the Fortran 90 interface." + env['FORTRAN'] = '' + print("INFO: Skipping compilation of the Fortran 90 interface.") if 'gfortran' in env['FORTRAN']: env['FORTRANMODDIRPREFIX'] = '-J' @@ -1059,9 +1060,9 @@ env['FORTRANMODDIR'] = '${TARGET.dir}' env = conf.Finish() if env['VERBOSE']: - print '-------------------- begin config.log --------------------' - print open('config.log').read() - print '--------------------- end config.log ---------------------' + print('-------------------- begin config.log --------------------') + print(open('config.log').read()) + print('--------------------- end config.log ---------------------') env['python_cmd_esc'] = quoted(env['python_cmd']) @@ -1070,9 +1071,9 @@ cython_min_version = LooseVersion('0.23') numpy_min_test_version = LooseVersion('1.8.1') env['install_python2_action'] = '' if env['python_package'] == 'new': - print ("WARNING: The 'new' option for the Python package is " - "deprecated and will be removed in the future. Use " - "'full' instead.") + print("WARNING: The 'new' option for the Python package is " + "deprecated and will be removed in the future. Use " + "'full' instead.") env['python_package'] = 'full' # Allow 'new' as a synonym for 'full' warn_no_python = False python_message = '' @@ -1097,7 +1098,7 @@ if env['python_package'] in ('full', 'default'): cython_min_version)) warn_no_python = True else: - print 'INFO: Using Cython version {0}.'.format(cython_version) + print('INFO: Using Cython version {0}.'.format(cython_version)) # Test to see if we can import the specified array module script = '\n'.join(("from __future__ import print_function", @@ -1123,13 +1124,13 @@ if env['python_package'] in ('full', 'default'): info = getCommandOutput(env['python_cmd'], '-c', script) except OSError as err: if env['VERBOSE']: - print 'Error checking for Python 2:' - print err + print('Error checking for Python 2:') + print(err) warn_no_python = True except subprocess.CalledProcessError as err: if env['VERBOSE']: - print 'Error checking for Python 2:' - print err, err.output + print('Error checking for Python 2:') + print(err, err.output) warn_no_python = True else: (env['python_version'], numpy_version, @@ -1139,30 +1140,30 @@ if env['python_package'] in ('full', 'default'): python_message += "NumPy for Python {0} not found.\n".format(env['python_version']) warn_no_python = True elif numpy_version < numpy_min_test_version: - print ("WARNING: The installed version of Numpy for Python {0} is not tested and " - "support is not guaranteed. Found {1} but {2} or newer is preferred".format( - env['python_version'], numpy_version, numpy_min_test_version)) + print("WARNING: The installed version of Numpy for Python {0} is not tested and " + "support is not guaranteed. Found {1} but {2} or newer is preferred".format( + env['python_version'], numpy_version, numpy_min_test_version)) else: - print 'INFO: Using NumPy version {0} for Python {1}.'.format( - numpy_version, env['python_version']) + print('INFO: Using NumPy version {0} for Python {1}.'.format( + numpy_version, env['python_version'])) if warn_no_python: if env['python_package'] == 'default': - print ('WARNING: Not building the full Python 2 package because the Python ' - '2 interpreter %r could not be found or a required dependency ' - '(e.g. numpy) was not found.' % env['python_cmd']) - print python_message + print('WARNING: Not building the full Python 2 package because the Python ' + '2 interpreter %r could not be found or a required dependency ' + '(e.g. numpy) was not found.' % env['python_cmd']) + print(python_message) env['python_package'] = 'minimal' else: - print ('ERROR: Could not execute the Python 2 interpreter %r or a required ' - 'dependency (e.g. numpy) could not be found.' % - env['python_cmd']) - print python_message + print('ERROR: Could not execute the Python 2 interpreter %r or a required ' + 'dependency (e.g. numpy) could not be found.' % + env['python_cmd']) + print(python_message) sys.exit(1) else: - print 'INFO: Building the full Python package for Python {0}'.format(env['python_version']) + print('INFO: Building the full Python package for Python {0}'.format(env['python_version'])) env['python_package'] = 'full' # Check for 3to2. See http://pypi.python.org/pypi/3to2 @@ -1184,15 +1185,15 @@ if env['python_package'] in ('full', 'default'): ret = getCommandOutput('3to2', '-l') except (OSError, subprocess.CalledProcessError) as err: if env['VERBOSE']: - print 'Error checking for 3to2:' - print err + print('Error checking for 3to2:') + print(err) ret = '' if 'print' in ret: env['python_convert_examples'] = True else: env['python_convert_examples'] = False - print ("WARNING: Couldn't find the 3to2 package. " - "Python 2 examples will not work correctly.") + print("WARNING: Couldn't find the 3to2 package. " + "Python 2 examples will not work correctly.") else: env['python_module_loc'] = '' @@ -1229,13 +1230,13 @@ if env['python3_package'] in ('y', 'default'): info = getCommandOutput(env['python3_cmd'], '-c', script) except OSError as err: if env['VERBOSE']: - print 'Error checking for Python 3:' - print err + print('Error checking for Python 3:') + print(err) warn_no_python3 = True except subprocess.CalledProcessError as err: if env['VERBOSE']: - print 'Error checking for Python 3:' - print err, err.output + print('Error checking for Python 3:') + print(err, err.output) warn_no_python3 = True else: (env['python3_version'], numpy3_version, @@ -1245,28 +1246,28 @@ if env['python3_package'] in ('y', 'default'): python3_message += "NumPy for Python {0} not found.\n".format(env['python3_version']) warn_no_python3 = True elif numpy3_version < numpy_min_test_version: - print ("WARNING: The installed version of Numpy for Python {0} is not tested and " - "support is not guaranteed. Found {1} but {2} or newer is preferred".format( - env['python3_version'], numpy3_version, numpy_min_test_version)) + print("WARNING: The installed version of Numpy for Python {0} is not tested and " + "support is not guaranteed. Found {1} but {2} or newer is preferred".format( + env['python3_version'], numpy3_version, numpy_min_test_version)) else: - print 'INFO: Using NumPy version {0} for Python {1}.'.format( - numpy3_version, env['python3_version']) + print('INFO: Using NumPy version {0} for Python {1}.'.format( + numpy3_version, env['python3_version'])) if warn_no_python3: if env['python3_package'] == 'default': - print ('INFO: Not building the Python 3 package because the Python ' - '3 interpreter %r could not be found or a required dependency ' - '(e.g. numpy) was not found.' % env['python3_cmd']) - print python3_message + print('INFO: Not building the Python 3 package because the Python ' + '3 interpreter %r could not be found or a required dependency ' + '(e.g. numpy) was not found.' % env['python3_cmd']) + print(python3_message) env['python3_package'] = 'n' else: - print ('ERROR: Could not execute the Python 3 interpreter %r or a ' - 'required dependency (e.g. numpy) could not be found.' % - env['python3_cmd']) - print python3_message + print('ERROR: Could not execute the Python 3 interpreter %r or a ' + 'required dependency (e.g. numpy) could not be found.' % + env['python3_cmd']) + print(python3_message) sys.exit(1) else: - print 'INFO: Building Python package for Python {0}'.format(env['python3_version']) + print('INFO: Building Python package for Python {0}'.format(env['python3_version'])) env['python3_package'] = 'y' @@ -1277,7 +1278,7 @@ if env['matlab_path'] != '' and env['matlab_toolbox'] == 'default': if env['matlab_toolbox'] == 'y': matPath = env['matlab_path'] if matPath == '': - print "ERROR: Unable to build the Matlab toolbox because 'matlab_path' has not been set." + print("ERROR: Unable to build the Matlab toolbox because 'matlab_path' has not been set.") sys.exit(1) if env['blas_lapack_libs']: @@ -1298,8 +1299,8 @@ if env['matlab_toolbox'] == 'y': if not (os.path.isdir(matPath) and os.path.isdir(pjoin(matPath, 'extern'))): - print """ERROR: Path set for 'matlab_path' is not correct.""" - print """ERROR: Path was: '%s'""" % matPath + print("""ERROR: Path set for 'matlab_path' is not correct.""") + print("""ERROR: Path was: '%s'""" % matPath) sys.exit(1) @@ -1612,15 +1613,15 @@ if 'samples' in COMMAND_LINE_TARGETS or addInstallActions: build_samples = Alias('samples', sampleTargets) def postBuildMessage(target, source, env): - print "*******************************************************" - print "Compilation completed successfully.\n" - print "- To run the test suite, type 'scons test'." + print("*******************************************************") + print("Compilation completed successfully.\n") + print("- To run the test suite, type 'scons test'.") if os.name == 'nt': - print "- To install, type 'scons install'." - print "- To create a Windows MSI installer, type 'scons msi'." + print("- To install, type 'scons install'.") + print("- To create a Windows MSI installer, type 'scons msi'.") else: - print "- To install, type '[sudo] scons install'." - print "*******************************************************" + print("- To install, type '[sudo] scons install'.") + print("*******************************************************") finish_build = env.Command('finish_build', [], postBuildMessage) env.Depends(finish_build, buildTargets) @@ -1639,7 +1640,7 @@ def postInstallMessage(target, source, env): env['matlab_sample_loc'] = pjoin(env['ct_sampledir'], 'matlab') env['matlab_ctpath_loc'] = pjoin(env['ct_matlab_dir'], 'ctpath.m') - print """ + print(""" Cantera has been successfully installed. File locations: @@ -1648,36 +1649,36 @@ File locations: library files %(ct_libdir)s C++ headers %(ct_incroot)s samples %(ct_sampledir)s - data files %(ct_datadir)s""" % env, + data files %(ct_datadir)s""" % env, end='') if env['python_package'] == 'full': - print """ + print(""" Python 2 package (cantera) %(python_module_loc)s - Python 2 samples %(python_example_loc)s""" % env, + Python 2 samples %(python_example_loc)s""" % env, end='') elif warn_no_python: - print """ + print(""" ################################################################# WARNING: the Cantera Python package was not installed because the prerequisites (Cython and NumPy) could not be found. - #################################################################""" + #################################################################""") if env['python3_package'] == 'y': - print """ + print(""" Python 3 package (cantera) %(python3_module_loc)s - Python 3 samples %(python3_example_loc)s""" % env, + Python 3 samples %(python3_example_loc)s""" % env, end='') if env['matlab_toolbox'] == 'y': - print """ + print(""" Matlab toolbox %(ct_matlab_dir)s Matlab samples %(matlab_sample_loc)s An m-file to set the correct matlab path for Cantera is at: %(matlab_ctpath_loc)s - """ % env, + """ % env, end='') if os.name != 'nt': - print """ + print(""" setup script %(ct_bindir)s/setup_cantera The setup script configures the environment for Cantera. It is recommended that @@ -1686,9 +1687,9 @@ you run this script by typing: source %(ct_bindir)s/setup_cantera before using Cantera, or else include its contents in your shell login script. - """ % env + """ % env) else: - print '' + print('') finish_install = env.Command('finish_install', [], postInstallMessage) env.Depends(finish_install, installTargets) @@ -1793,9 +1794,9 @@ if any(target.startswith('test') for target in COMMAND_LINE_TARGETS): SConscript('test_problems/SConscript') if 'test-help' in COMMAND_LINE_TARGETS: - print '\n*** Available tests ***\n' + print('\n*** Available tests ***\n') for name in env['testNames']: - print 'test-%s' % name + print('test-%s' % name) sys.exit(0) Alias('test', env['test_results']) @@ -1804,6 +1805,6 @@ if any(target.startswith('test') for target in COMMAND_LINE_TARGETS): if 'dump' in COMMAND_LINE_TARGETS: import pprint # Typical usage: 'scons build dump' - print 'os.environ:\n', pprint.pprint(dict(os.environ)) - print 'env.Dump():\n', env.Dump() + print('os.environ:\n', pprint.pprint(dict(os.environ))) + print('env.Dump():\n', env.Dump()) sys.exit(0) diff --git a/doc/SConscript b/doc/SConscript index 59a026df1..4475e65a3 100644 --- a/doc/SConscript +++ b/doc/SConscript @@ -1,3 +1,4 @@ +from __future__ import print_function from buildutils import * import ast @@ -60,7 +61,7 @@ def extract_matlab_docstring(mfile, level): elif level == 1: docstring = " .. mat:function:: " else: - print "Unknown level for MATLAB documentation." + print("Unknown level for MATLAB documentation.") sys.exit(1) # The leader is the number of spaces at the beginning of a regular line @@ -109,7 +110,7 @@ def get_function_name(str): elif str.startswith('classdef '): sig = str[len('classdef '):] else: - print "Unknown function declaration in MATLAB document", str + print("Unknown function declaration in MATLAB document", str) # Split the function signature on the equals sign, if it exists. # We don't care about what comes before the equals sign, since diff --git a/platform/posix/coverage.py b/platform/posix/coverage.py index 4ff08a231..f6143a3e5 100755 --- a/platform/posix/coverage.py +++ b/platform/posix/coverage.py @@ -4,6 +4,7 @@ Collect test coverage data and generate an html report. """ +from __future__ import print_function import os import subprocess import shutil @@ -55,7 +56,7 @@ def collect(): """ sourcedirs = getDirectories() if not sourcedirs: - print "Warning! Didn't find any coverage data." + print("Warning! Didn't find any coverage data.") return command = ['lcov', '-c', diff --git a/site_scons/buildutils.py b/site_scons/buildutils.py index 059dd2c9b..51fd25f3d 100644 --- a/site_scons/buildutils.py +++ b/site_scons/buildutils.py @@ -1,3 +1,4 @@ +from __future__ import print_function import os from os.path import join as pjoin from os.path import normpath @@ -49,8 +50,8 @@ class ConfigBuilder(object): def __call__(self, source, target, env): for s, t in zip(source, target): - config_h_in = file(str(s), "r") - config_h = file(str(t), "w") + config_h_in = open(str(s), "r") + config_h = open(str(t), "w") config_h.write(config_h_in.read() % self.defines) config_h_in.close() @@ -58,12 +59,12 @@ class ConfigBuilder(object): self.print_config(str(t)) def print_config(self, filename): - print 'Generating %s with the following settings:' % filename - for key, val in sorted(self.defines.data.iteritems()): + print('Generating %s with the following settings:' % filename) + for key, val in sorted(self.defines.data.items()): if val is not None: - print " %-35s %s" % (key, val) + print(" %-35s %s" % (key, val)) for key in sorted(self.defines.undefined): - print " %-35s %s" % (key, '*undefined*') + print(" %-35s %s" % (key, '*undefined*')) class TestResults(object): @@ -84,7 +85,7 @@ class TestResults(object): '\n') else: failures = '' - print """ + print(""" ***************************** *** Testing Summary *** ***************************** @@ -97,7 +98,7 @@ Tests failed: %(failed)s passed=sum(self.passed.values()), failed=sum(self.failed.values()), skipped=len(self.tests), - failures=failures) + failures=failures)) if self.failed: raise SCons.Errors.BuildError(self, 'One or more tests failed.') @@ -149,7 +150,7 @@ def regression_test(target, source, env): cwd=dir, env=env['ENV']) if code: - print 'FAILED (program exit code:{0})'.format(code) + print('FAILED (program exit code:{0})'.format(code)) diff = 0 # Compare output files @@ -158,10 +159,10 @@ def regression_test(target, source, env): comparisons.append((blessedName,outputName)) for blessed,output in comparisons: - print """Comparing '%s' with '%s'""" % (blessed, output) + print("""Comparing '%s' with '%s'""" % (blessed, output)) d = compareFiles(env, pjoin(dir, blessed), pjoin(dir, output)) if d: - print 'FAILED' + print('FAILED') diff |= d del testResults.tests[env['active_test_name']] @@ -172,7 +173,7 @@ def regression_test(target, source, env): testResults.failed[env['active_test_name']] = 1 else: - print 'PASSED' + print('PASSED') open(target[0].path, 'w').write(time.asctime()+'\n') testResults.passed[env['active_test_name']] = 1 @@ -243,7 +244,7 @@ def compareTextFiles(env, file1, file2): abserr = abs(num1-num2) relerr = abserr / (0.5 * abs(num1 + num2) + atol) if abserr > (1.1*delta + atol) and relerr > rtol: - print 'Values differ: {0: 14g} {1: 14g}; rel. err = {2:.3e}; abs. err = {3:.3e}'.format(num1, num2, relerr, abserr) + print('Values differ: {0: 14g} {1: 14g}; rel. err = {2:.3e}; abs. err = {3:.3e}'.format(num1, num2, relerr, abserr)) allMatch = False break except Exception as e: @@ -259,10 +260,10 @@ def compareTextFiles(env, file1, file2): # Try the comparison again diff = list(difflib.unified_diff(text1, text2)) if diff: - print 'Found differences between %s and %s:' % (file1, file2) - print '>>>' - print '\n'.join(diff) - print '<<<' + print('Found differences between %s and %s:' % (file1, file2)) + print('>>>') + print('\n'.join(diff)) + print('<<<') return 1 return 0 @@ -314,7 +315,7 @@ def compareCsvFiles(env, file1, file2): try: import numpy as np except ImportError: - print 'WARNING: skipping .csv diff because numpy is not installed' + print('WARNING: skipping .csv diff because numpy is not installed') return 0 # decide how many header lines to skip @@ -331,7 +332,7 @@ def compareCsvFiles(env, file1, file2): data1 = np.genfromtxt(file1, skip_header=headerRows, delimiter=',') data2 = np.genfromtxt(file2, skip_header=headerRows, delimiter=',') except (IOError, StopIteration) as e: - print e + print(e) return 1 try: @@ -340,21 +341,21 @@ def compareCsvFiles(env, file1, file2): env['test_csv_threshold'])) maxerror = np.nanmax(relerror.flat) except ValueError as e: - print e + print(e) return 1 tol = env['test_csv_tolerance'] if maxerror > tol: # Threshold based on printing 6 digits in the CSV file - print ("Files differ. %i / %i elements above specified tolerance (%f)" % - (np.sum(relerror > tol), relerror.size, tol)) - print ' row col reference test rel. error' - print ' ---- ---- ------------ ------------ ----------' + print("Files differ. %i / %i elements above specified tolerance (%f)" % + (np.sum(relerror > tol), relerror.size, tol)) + print(' row col reference test rel. error') + print(' ---- ---- ------------ ------------ ----------') for i,j in itertools.product(*map(range, relerror.shape)): if relerror[i,j] > tol: row = i + headerRows + 1 col = j + 1 - print (' % 4i % 4i % 12f % 12f % 10f' % - (row, col, data1[i,j], data2[i,j], relerror[i,j])) + print(' % 4i % 4i % 12f % 12f % 10f' % + (row, col, data1[i,j], data2[i,j], relerror[i,j])) return 1 else: return 0 @@ -514,23 +515,23 @@ def listify(value): Convert an option specified as a string to a list, using spaces as delimiters. Passes lists transparently. """ - if isinstance(value, types.StringTypes): - return value.split() - else: + if isinstance(value, (list, tuple)): # Already a sequence. Return as a list return list(value) - + else: + # assume `value` is a string + return value.split() def removeFile(name): """ Remove file (if it exists) and print a log message """ if os.path.exists(name): - print 'Removing file "%s"' % name + print('Removing file "%s"' % name) os.remove(name) def removeDirectory(name): """ Remove directory recursively and print a log message """ if os.path.exists(name): - print 'Removing directory "%s"' % name + print('Removing directory "%s"' % name) shutil.rmtree(name) def ipdb(): @@ -584,9 +585,9 @@ def getSpawn(env): data, err = proc.communicate() rv = proc.wait() if rv: - print "=====" - print err - print "=====" + print("=====") + print(err) + print("=====") return rv return ourSpawn @@ -601,7 +602,10 @@ def getCommandOutput(cmd, *args): # Can cause problems when trying to run a different Python interpreter del environ['PYTHONHOME'] data = subprocess.check_output([cmd] + list(args), env=environ) - return data.strip() + if sys.version_info.major == 3: + return data.strip().decode('utf-8') + else: + return data.strip() # Monkey patch for SCons Cygwin bug # See http://scons.tigris.org/issues/show_bug.cgi?id=2664 diff --git a/site_scons/site_tools/gch.py b/site_scons/site_tools/gch.py index 65328d43c..0819db63d 100644 --- a/site_scons/site_tools/gch.py +++ b/site_scons/site_tools/gch.py @@ -39,7 +39,7 @@ # env['Gch'] = env.Gch(target='common/includes/all.h.gch', source=env['precompiled_header']) - +from __future__ import print_function import SCons.Action import SCons.Builder import SCons.Scanner.C @@ -79,7 +79,7 @@ def header_path(node): raise SCons.Errors.StopError("{0} file doesn't have .gch extension".format(h_path)) def dump_node(node): - print '~Attrs for '+str(node) + print('~Attrs for '+str(node)) for attr_name in sorted(dir(node)): if attr_name[0] == '_': continue @@ -87,7 +87,7 @@ def dump_node(node): if type(attr) == list: attr = [str(x) for x in attr] if not callable(attr): - print '~',attr_name+":", attr + print('~',attr_name+":", attr) inc_re = re.compile(r'#include\s*"([a-zA-Z0-9._]+)"') @@ -117,7 +117,7 @@ def pch_emitter(pch_env_key, target, source, env): if env.get(pch_env_key): if _directly_includes_header(src, os.path.basename(env['precompiled_header'].path)): if 'explain' in env.GetOption('debug'): - print 'Found dep. on pch: ', source[0], ' -> ', env[pch_env_key] + print('Found dep. on pch: ', source[0], ' -> ', env[pch_env_key]) env.Depends(target, env[pch_env_key]) return (target, source) diff --git a/site_scons/wxsgen.py b/site_scons/wxsgen.py index ec3df0c27..e71571922 100644 --- a/site_scons/wxsgen.py +++ b/site_scons/wxsgen.py @@ -1,3 +1,4 @@ +from __future__ import print_function import os, sys import uuid import xml.etree.ElementTree as et @@ -199,7 +200,7 @@ def indent(elem, level=0): def usage(): - print "Usage: wxsgen " + print("Usage: wxsgen ") if __name__ == '__main__': if len(sys.argv) != 3: diff --git a/test/SConscript b/test/SConscript index 42977e779..8ebd0806d 100644 --- a/test/SConscript +++ b/test/SConscript @@ -1,3 +1,4 @@ +from __future__ import print_function from buildutils import * import subprocess from xml.etree import ElementTree @@ -56,7 +57,7 @@ def addTestProgram(subdir, progName, env_vars={}): code = subprocess.call(cmd, env=env['ENV'], cwd=workDir) if code: - print "FAILED: Test '{0}' exited with code {1}".format(progName, code) + print("FAILED: Test '{0}' exited with code {1}".format(progName, code)) else: # Test was successful open(passedFile.path, 'w').write(time.asctime()+'\n') @@ -111,8 +112,8 @@ def addPythonTest(testname, subdir, script, interpreter, outfile, os.remove(outfile) environ = dict(env['ENV']) - for k,v in env_vars.iteritems(): - print k,v + for k,v in env_vars.items(): + print(k,v) environ[k] = v code = subprocess.call([env.subst(interpreter), source[0].abspath] + args.split(), env=environ) @@ -179,9 +180,9 @@ def addMatlabTest(script, testName, dependencies=None, env_vars=()): matlabOptions + ['-r', runCommand], env=environ, cwd=Dir('#test/matlab').abspath) results = open(outfile).read() - print '-------- Matlab test results --------' - print results - print '------ end Matlab test results ------' + print('-------- Matlab test results --------') + print(results) + print('------ end Matlab test results ------') if 'FAILED' in results: testResults.failed[passedFile.name] = 1 else: