From 338a54f1018e6e52e74c731375f46e796c227873 Mon Sep 17 00:00:00 2001 From: Ray Speth Date: Mon, 17 Mar 2014 02:05:09 +0000 Subject: [PATCH] [SCons] Simplify implementation of changes in r2810 Use the correct platform-independent path separator instead of assuming that it is ':'. Determine the PYTHONPATH variable in a single place for each Python version. --- SConstruct | 35 +++++++++++++++-------------------- test/SConscript | 35 +++-------------------------------- test_problems/SConscript | 26 ++------------------------ 3 files changed, 20 insertions(+), 76 deletions(-) diff --git a/SConstruct b/SConstruct index 631365cfc..c092c01a5 100644 --- a/SConstruct +++ b/SConstruct @@ -135,10 +135,7 @@ if os.name == 'nt': else: toolchain = ['default'] -# -# Go get the environment especially the toolchain which we will use to compile -# the code -# + env = Environment(tools=toolchain+['textfile', 'subst', 'recursiveInstall', 'wix'], ENV={'PATH': os.environ['PATH']}, toolchain=toolchain, @@ -644,19 +641,12 @@ if env['env_vars'] == 'all': if 'PYTHONHOME' in env['ENV']: del env['ENV']['PYTHONHOME'] elif env['env_vars']: - for name_n in env['env_vars'].split(','): - # - # Strip name of leading and trailer white space. This is a known error that has led to problems. - # - name = name_n.strip() - # - # Add name to the saved environment for later use, getting the environmental value - # - if name in os.environ : + for name in listify(env['env_vars']): + if name in os.environ: env['ENV'][name] = os.environ[name] elif name not in defaults.env_vars: - print 'WARNING: failed to propagate environment variable', name - print ' Go back and edit cantera.conf file' + 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] @@ -876,6 +866,11 @@ if env['python_package'] == 'new': warnNoPython = False if env['python_package'] in ('full','default'): + # The directory within the source tree which will contain the Python 2 module + env['pythonpath_build2'] = Dir('build/python2').abspath + if 'PYTHONPATH' in env['ENV']: + env['pythonpath_build2'] += os.path.pathsep + env['ENV']['PYTHONPATH'] + # Check for Cython: try: import Cython @@ -946,6 +941,11 @@ else: # Python 3 Package Settings if env['python3_package'] in ('y', 'default'): + # The directory within the source tree which will contain the Python 3 module + env['pythonpath_build3'] = Dir('build/python3').abspath + if 'PYTHONPATH' in env['ENV']: + env['pythonpath_build3'] += os.path.pathsep + env['ENV']['PYTHONPATH'] + # See if we can execute the Python 3 interpreter try: script = '\n'.join(("from distutils.sysconfig import *", @@ -1565,8 +1565,3 @@ if any(target.startswith('test') for target in COMMAND_LINE_TARGETS): for name in env['testNames']: print 'test-%s' % name sys.exit(0) - - -#import pdb; pdb.set_trace() - - diff --git a/test/SConscript b/test/SConscript index 00a47426e..70dd4a96e 100644 --- a/test/SConscript +++ b/test/SConscript @@ -179,29 +179,11 @@ def addMatlabTest(script, testName, dependencies=None, env_vars=()): return run_program if localenv['python_package'] in ('full', 'minimal'): - python_env_vars = {'PYTHONPATH': Dir('#build/python2').abspath, + python_env_vars = {'PYTHONPATH': localenv['pythonpath_build2'], 'PYTHON_CMD': localenv.subst('$python_cmd')} - # - # I guess we need to install the current python installation which is located - # within our own build directory in front of the existing PYTHONPATH which - # contains locations for numpy and other packages - # - if 'PYTHONPATH' in env['ENV'] : - tmpp = Dir('#build/python2').abspath + ':'+ env['ENV']['PYTHONPATH'] - else: - tmpp = Dir('#build/python2').abspath - python_env_vars['PYTHONPATH'] = tmpp - # print 'python_env_vars = ', python_env_vars['PYTHONPATH'] - # import pdb; pdb.set_trace() - elif localenv['python3_package'] == 'y': - python_env_vars = {'PYTHONPATH': Dir('#build/python3').abspath, + python_env_vars = {'PYTHONPATH': localenv['pythonpath_build3'], 'PYTHON_CMD': localenv.subst('$python3_cmd')} - if 'PYTHONPATH' in env['ENV'] : - tmpp = Dir('#build/python3').abspath + ':'+ env['ENV']['PYTHONPATH'] - else: - tmpp = Dir('#build/python3').abspath - python_env_vars['PYTHONPATH'] = tmpp else: python_env_vars = {} # Tests calling ck2cti or ctml_writer will fail @@ -221,16 +203,6 @@ def make_python_tests(version): # tests (test-cython2) for the main suite. for subset in python_subtests: name = 'cython%i-' %version + subset if subset else 'cython%i' % version - # - # Need to respect the incoming PYTHONPATH variable and to put the current install - # dir in front of PYTHONPATH - # - if 'PYTHONPATH' in env['ENV']: - tmpp = Dir('#build/python%i' % version).abspath + ":" + env['ENV']['PYTHONPATH'] - else: - tmpp = Dir('#build/python%i' % version).abspath - - pyTest = addPythonTest( name, 'python', 'runCythonTests.py', args=subset, @@ -239,8 +211,7 @@ def make_python_tests(version): dependencies=(localenv['python%i_module' % version] + localenv['python%i_extension' % version] + mglob(localenv, test_root, 'py')), - # env_vars={'PYTHONPATH':Dir('#build/python%i' % version).abspath}, - env_vars={'PYTHONPATH': tmpp }, + env_vars={'PYTHONPATH': localenv['pythonpath_build%s' % version]}, optional=bool(subset)) localenv.Alias('test-' + name, pyTest) env['testNames'].append(name) diff --git a/test_problems/SConscript b/test_problems/SConscript index f01cdd4aa..097f9feab 100644 --- a/test_problems/SConscript +++ b/test_problems/SConscript @@ -6,33 +6,11 @@ localenv.Prepend(CPPPATH=['#include', '#src', 'shared']) localenv.Append(CCFLAGS=env['warning_flags']) if localenv['python_package'] in ('full', 'minimal'): - tmp1 = pjoin(os.getcwd(), '..', 'build', 'python2') - # - # I guess we need to install the current python installation which is located - # within our own build directory in front of the existing PYTHONPATH which - # contains locations for numpy and other packages - # - if 'PYTHONPATH' in env['ENV'] : - tmpp = tmp1 + ':' + env['ENV']['PYTHONPATH'] - else: - tmpp = tmp1 - - localenv['ENV']['PYTHONPATH'] = tmpp + localenv['ENV']['PYTHONPATH'] = localenv['pythonpath_build2'] localenv['ENV']['PYTHON_CMD'] = localenv.subst('$python_cmd') haveConverters = True elif localenv['python3_package'] == 'y': - tmp1 = pjoin(os.getcwd(), '..', 'build', 'python3') - # - # I guess we need to install the current python installation which is located - # within our own build directory in front of the existing PYTHONPATH which - # contains locations for numpy and other packages - # - if 'PYTHONPATH' in env['ENV'] : - tmpp = tmp1 + ':' + env['ENV']['PYTHONPATH'] - else: - tmpp = tmp1 - - localenv['ENV']['PYTHONPATH'] = tmpp + localenv['ENV']['PYTHONPATH'] = localenv['pythonpath_build3'] localenv['ENV']['PYTHON_CMD'] = localenv.subst('$python3_cmd') haveConverters = True else: