From a0fdaa9f8a82161453f9a003809415356c856561 Mon Sep 17 00:00:00 2001 From: Ray Speth Date: Thu, 6 Sep 2012 19:58:22 +0000 Subject: [PATCH] SCons builds the new Python module with Python 2 and Python 3 simultaneously --- SConstruct | 14 ++++++------ interfaces/cython/.gitignore | 3 ++- interfaces/cython/SConscript | 41 ++++++++++++++++++++++++++++++------ 3 files changed, 44 insertions(+), 14 deletions(-) diff --git a/SConstruct b/SConstruct index 18d397b8f..54d0dca75 100644 --- a/SConstruct +++ b/SConstruct @@ -260,7 +260,7 @@ opts.AddVariables( (actually, only one file). The default behavior is to build the Python package if the required prerequisites (numpy) are installed.""", - 'default', ('full', 'minimal', 'none','default')), + 'default', ('new', 'full', 'minimal', 'none', 'default')), PathVariable( 'python_cmd', """Cantera needs to know where to find the Python interpreter. If @@ -769,7 +769,7 @@ env = conf.Finish() # Python 2 Package Settings -if env['python_package'] in ('full','default'): +if env['python_package'] in ('full','default','new'): # Test to see if we can import the specified array module warnNoPython = False if env['python_array_home']: @@ -783,9 +783,10 @@ if env['python_package'] in ('full','default'): env['python_array_include'] = '' print """INFO: Building the full Python package using %s.""" % env['python_array'] - env['python_package'] = 'full' + if env['python_package'] == 'default': + env['python_package'] = 'full' except ImportError: - if env['python_package'] == 'full': + if env['python_package'] in ('full', 'new'): print ("""ERROR: Unable to find the array package """ """'%s' required by the full Python package.""" % env['python_array']) sys.exit(1) @@ -1205,9 +1206,8 @@ if env['python_package'] in ('full','minimal'): VariantDir('build/src/python', 'src/python', duplicate=0) SConscript('build/src/python/SConscript') -if env['python3_package'] == 'y': - VariantDir('build/python3', 'interfaces/cython', duplicate=0) - SConscript('build/cython/SConscript') +if env['python3_package'] == 'y' or env['python_package'] == 'new': + SConscript('interfaces/cython/SConscript') SConscript('build/src/apps/SConscript') diff --git a/interfaces/cython/.gitignore b/interfaces/cython/.gitignore index ad84b9e98..f836ae32b 100644 --- a/interfaces/cython/.gitignore +++ b/interfaces/cython/.gitignore @@ -2,4 +2,5 @@ cantera/*.cpp cantera/*.c cantera/data/*.cti cantera/data/*.xml -setup.py +setup2.py +setup3.py diff --git a/interfaces/cython/SConscript b/interfaces/cython/SConscript index c48de9dac..05ac4cf67 100644 --- a/interfaces/cython/SConscript +++ b/interfaces/cython/SConscript @@ -26,24 +26,53 @@ if localenv['python3_package'] == 'y': "print(get_config_var('SO'))", "print(numpy.get_include())"))) - module_extension, localenv['python3_array_include'] = info.split('\n') + module_ext, numpy_include = info.split('\n') - incDirs = (".", "../../include", localenv['python3_array_include'], + incDirs = (".", "../../include", numpy_include, localenv['sundials_include'], localenv['boost_inc_dir']) localenv['py_include_dirs'] = repr([x for x in incDirs if x]) - - make_setup = localenv.SubstFile('#interfaces/cython/setup.py', + make_setup = localenv.SubstFile('#interfaces/cython/setup3.py', '#interfaces/cython/setup.py.in') build(make_setup) opts = '--build-lib=../../build/python3 --build-temp=../../build/temp' - mod = build(localenv.Command('cantera/_cantera%s' % module_extension, - 'setup.py', + mod = build(localenv.Command('#build/python3/cantera/_cantera%s' % module_ext, + 'setup3.py', 'cd interfaces/cython && ' '$python3_cmd $SOURCE.name build %s' % opts)) localenv.AddPreAction(mod, Delete('interfaces/cython/cantera/_cantera.cpp')) + localenv.Depends(mod, localenv['cantera_staticlib']) + for f in mglob(localenv, 'cantera', 'pyx', 'pxd'): + localenv.Depends(mod, f) + +if localenv['python_package'] == 'new': + info = getCommandOutput(localenv['python_cmd'], '-c', + '\n'.join(("from distutils.sysconfig import *", + "import numpy", + "print get_config_var('SO')", + "print numpy.get_include()"))) + + module_ext, numpy_include = info.split('\n') + + incDirs = (".", "../../include", numpy_include, + localenv['sundials_include'], localenv['boost_inc_dir']) + localenv['py_include_dirs'] = repr([x for x in incDirs if x]) + + make_setup = localenv.SubstFile('#interfaces/cython/setup2.py', + '#interfaces/cython/setup.py.in') + build(make_setup) + + opts = '--build-lib=../../build/python2 --build-temp=../../build/temp' + mod = build(localenv.Command('#build/python2/cantera/_cantera%s' % module_ext, + 'setup2.py', + 'cd interfaces/cython && ' + '$python_cmd $SOURCE.name build %s' % opts)) + + localenv.AddPreAction(mod, Delete('interfaces/cython/cantera/_cantera.cpp')) + + localenv.Depends(mod, localenv['cantera_staticlib']) for f in mglob(localenv, 'cantera', 'pyx', 'pxd'): localenv.Depends(mod, f)