From 49ee5391e002d4d44d2301237dc3fbd098d5215a Mon Sep 17 00:00:00 2001 From: Ray Speth Date: Wed, 14 Dec 2011 19:34:53 +0000 Subject: [PATCH] Fixed building / installation of Python module in Windows --- Cantera/clib/SConscript | 2 ++ Cantera/python/SConscript | 22 +++++++++++++--------- Cantera/python/setup.py.in | 15 ++++++--------- SConstruct | 5 +---- 4 files changed, 22 insertions(+), 22 deletions(-) diff --git a/Cantera/clib/SConscript b/Cantera/clib/SConscript index 21d1f10d4..c78bfecd6 100644 --- a/Cantera/clib/SConscript +++ b/Cantera/clib/SConscript @@ -6,6 +6,8 @@ localenv = env.Clone() lib = localenv.SharedLibrary(pjoin('../../lib', 'clib'), source=mglob(localenv, 'src', 'cpp'), LIBS=env['cantera_libs']) +env['clib_shared'] = lib + inst = localenv.Install('$ct_libdir', lib) buildTargets.extend(lib) installTargets.extend(inst) diff --git a/Cantera/python/SConscript b/Cantera/python/SConscript index f9b49b7ac..82d6f9ab4 100644 --- a/Cantera/python/SConscript +++ b/Cantera/python/SConscript @@ -23,24 +23,28 @@ if env['python_package'] == 'full': SHLIBSUFFIX=gcv('SO')) buildTargets.extend(pymodule) localenv.Depends(pymodule, make_setup) + if localenv['OS'] == 'Windows': + for file in localenv['clib_shared']: + dest = pjoin('Cantera', 'python', 'Cantera', file.name) + localenv.AddPreAction(pymodule,Copy(dest, file)) + elif env['python_package'] == 'minimal': pymodule = make_setup -localenv.AddPostAction(make_setup, 'cd Cantera/python; $python_cmd setup.py build') +moddir = pjoin('Cantera', 'python') +localenv.AddPostAction(make_setup, + 'cd %s && $python_cmd setup.py build' % moddir) # Install the Python module -if env['cantera_python_home'] is None: +if env['python_prefix']: + # A specific location for the Cantera python module has been specified + extra = '--prefix="%s"' % env['python_prefix'] +else: # Install Python module in the default location extra = '' -elif env['cantera_python_home'] == env['prefix']: - # Cantera is being installed with a non-default prefix - extra = '--prefix=' + env['prefix'] -else: - # A specific location for the Cantera python module has been specified - extra = '--home=' + env['cantera_python_home'] inst = localenv.Command('dummy', pymodule, - 'cd Cantera/python; $python_cmd setup.py install %s' % extra) + 'cd %s && $python_cmd setup.py install %s' % (moddir,extra)) installTargets.extend(inst) if env['python_package'] == 'full': diff --git a/Cantera/python/setup.py.in b/Cantera/python/setup.py.in index f6fc6884d..00a40d43a 100644 --- a/Cantera/python/setup.py.in +++ b/Cantera/python/setup.py.in @@ -1,13 +1,10 @@ -import sys -import string from distutils.core import setup, Extension +from distutils.sysconfig import get_config_var +import os -platform = sys.platform - -# values: -# 0 do nothing -# 1 install only ctml_writer.py -# 2 install full package +dataFiles = ['_cantera%s' % get_config_var('SO')] +if os.name == 'nt': + dataFiles.append('clib.dll') if '@python_package@' == 'full': setup(name="Cantera", @@ -21,7 +18,7 @@ if '@python_package@' == 'full': package_dir = {'MixMaster':'../../apps/MixMaster'}, packages = ["","Cantera","Cantera.OneD", "MixMaster","MixMaster.Units"], - package_data = {'Cantera': ['_cantera.so']}) + package_data = {'Cantera': dataFiles}) elif '@python_package@' == 'minimal': setup(name="Cantera CTI File Processor", version="@cantera_version@", diff --git a/SConstruct b/SConstruct index 30de6e127..a39863568 100644 --- a/SConstruct +++ b/SConstruct @@ -118,7 +118,7 @@ opts.AddVariables( the home directory for numpy.""", '', PathVariable.PathAccept), PathVariable( - 'cantera_python_home', + 'python_prefix', """If you want to install the Cantera Python package somewhere other than the default 'site-packages' directory within the Python library directory, then set this to the desired @@ -482,9 +482,6 @@ env['HAS_MATH_H_ERF'] = conf.CheckDeclaration('erf', '#include ', 'C++') env['HAS_BOOST_MATH'] = conf.CheckCXXHeader('boost/math/special_functions/erf.hpp', '<>') env = conf.Finish() -if env['cantera_python_home'] == '' and env['prefix'] != defaults.prefix: - env['cantera_python_home'] = env['prefix'] - if env['python_package'] in ('full','default'): # Test to see if we can import the specified array module warnNoPython = False