[SCons] Fix Python module path in setup_cantera and post-install message

In particular, this fixes paths for Linux distros that put Python modules in
'lib64/pythonX.Y/site-packages'.

Also fixes the reported installation path for the Python module on Windows.
This commit is contained in:
Ray Speth 2013-07-29 01:37:57 +00:00
parent 9a8dbf75f8
commit f320290c51
6 changed files with 54 additions and 30 deletions

View file

@ -929,7 +929,7 @@ if env['python3_package'] in ('y', 'default'):
script = '\n'.join(("from distutils.sysconfig import *",
"import site",
"print(get_python_version())",
"try:"
"try:",
" print(site.getusersitepackages())",
"except AttributeError:",
" print(site.USER_SITE)",
@ -1081,12 +1081,6 @@ if env['layout'] == 'debian':
env['inst_python_bindir'] = pjoin(base, 'cantera-python', 'usr', 'bin')
env['python_prefix'] = pjoin(base, 'cantera-python', 'usr')
env['python_module_loc'] = pjoin(env['python_prefix'],
'python%i.%i' % sys.version_info[:2],
'dist-packages')
env['python3_module_loc'] = env.subst(pjoin('${python3_prefix}',
'python${python3_version}',
'dist-packages'))
env['ct_datadir'] = '/usr/share/cantera/data'
else:
env['inst_libdir'] = pjoin(instRoot, 'lib')
@ -1094,18 +1088,7 @@ else:
env['inst_python_bindir'] = pjoin(instRoot, 'bin')
env['inst_incdir'] = pjoin(instRoot, 'include', 'cantera')
env['inst_incroot'] = pjoin(instRoot, 'include')
if env['python_prefix'] == 'USER':
env['python_module_loc'] = env['python_usersitepackages']
else:
env['python_module_loc'] = pjoin(env['python_prefix'], 'lib',
'python%i.%i' % sys.version_info[:2],
'site-packages')
if env['python3_package'] == 'y' and env['python3_prefix'] == 'USER':
env['python3_module_loc'] = env['python3_usersitepackages']
else:
env['python3_module_loc'] = env.subst(pjoin('${python3_prefix}', 'lib',
'python${python3_version}',
'site-packages'))
if env['layout'] == 'compact':
env['inst_matlab_dir'] = pjoin(instRoot, 'matlab', 'toolbox')
env['inst_datadir'] = pjoin(instRoot, 'data')
@ -1429,9 +1412,14 @@ build_cantera = Alias('build', finish_build)
Default('build')
def postInstallMessage(target, source, env):
env['python_module_loc'] = env.subst(env['python_module_loc'])
if env['python_package'] == 'none':
env['python_module_loc'] = 'NONE'
if env['python3_package'] == 'y':
env['python3_example_loc'] = pjoin(env['python3_module_loc'], 'cantera', 'examples')
env['python_example_loc'] = pjoin(env['python_module_loc'], 'cantera', 'examples')
env['python3_example_loc'] = pjoin(env['python3_module_loc'], 'cantera', 'examples')
env['matlab_sample_loc'] = pjoin(env['ct_matlab_dir'], 'matlab')
env['matlab_ctpath_loc'] = pjoin(env['prefix'], 'matlab', 'ctpath.m')
print """
@ -1463,7 +1451,7 @@ File locations:
if env['python3_package'] == 'y':
print """
Python 3 package (cantera) %(python3_module_loc)s
Python 3 samples %(python3_module_loc)s""" % env,
Python 3 samples %(python3_example_loc)s""" % env,
if env['matlab_toolbox'] == 'y':
print """

View file

@ -73,17 +73,32 @@ def install_module(prefix, python_version):
extra = ''
major = python_version[0]
ver = '3' if major == '3' else ''
dummy = 'dummy' + major
if localenv['PYTHON_INSTALLER'] == 'direct':
install(localenv.Command, dummy, mod,
build_cmd + ' install --record ../../build/python%s-installed-files.txt %s' % (major, extra))
mod_inst = install(localenv.Command, dummy, mod,
build_cmd + ' install %s' % extra +
' --record ../../build/python%s-installed-files.txt' % major)
global_env = env
def find_module_dir(target, source, env):
check = pjoin('cantera','__init__.py')
for filename in open('build/python%s-installed-files.txt' % major).readlines():
filename = filename.strip()
if filename.endswith(check):
filename = filename.replace(check,'')
global_env['python%s_module_loc' % ver] = os.path.normpath(filename)
break
localenv.AlwaysBuild(localenv.AddPostAction(mod_inst, find_module_dir))
elif localenv['PYTHON_INSTALLER'] == 'debian':
install(localenv.Command, dummy, mod,
build_cmd + ' install --install-layout=deb --no-compile %s' % extra)
env['python%s_module_loc' % ver] = '<unspecified>'
elif localenv['PYTHON_INSTALLER'] == 'binary':
install(localenv.Command, dummy, mod,
build_cmd + ' bdist_msi --dist-dir=../..' +
' --target-version=%s' % python_version)
env['python%s_module_loc' % ver] = '<unspecified>'
libDirs = ('../../build/lib', localenv['sundials_libdir'],

View file

@ -10,9 +10,15 @@ localenv = env.Clone()
# 'setup_cantera'
if localenv['layout'] != 'debian':
v = sys.version_info
if localenv['python_prefix'] == 'USER':
localenv['python_module_loc'] = ''
target = build(localenv.SubstFile('setup_cantera', 'setup_cantera.in'))
def copy_var(target, source, env):
if env['python_prefix'] == 'USER':
env['python_module_loc_sc'] = ''
else:
env['python_module_loc_sc'] = env['python_module_loc']
target = env.SubstFile('setup_cantera', 'setup_cantera.in')
localenv.AddPreAction(target, copy_var)
install('$inst_bindir', target)
# 'mixmaster'

View file

@ -26,7 +26,7 @@ if [ "@matlab_toolbox@" = "y" ]; then
export MATLABPATH
fi
if [ "@python_module_loc@" != "" ]; then
if [ "@python_module_loc_sc@" != "" ]; then
if [ -z $PYTHONPATH ]; then
PYTHONPATH=@python_module_loc@
else

View file

@ -13,6 +13,7 @@ import itertools
import SCons.Errors
from distutils.version import LooseVersion
import distutils.sysconfig
class DefineDict(object):
"""

View file

@ -87,15 +87,29 @@ else:
extra = ''
if localenv['PYTHON_INSTALLER'] == 'direct':
install(localenv.Command, 'dummy', pymodule,
'cd %s && $python_cmd setup.py install --record ../../build/python-installed-files.txt %s' % (moddir,extra))
mod_inst = install(localenv.Command, 'dummy', pymodule,
'cd %s && $python_cmd setup.py install %s' % (moddir,extra) +
' --record ../../build/python-installed-files.txt')
global_env = env
def find_module_dir(target, source, env):
check = pjoin('Cantera','__init__.py')
for filename in open('build/python-installed-files.txt').readlines():
filename = filename.strip()
if filename.endswith(check):
filename = filename.replace(check,'')
global_env['python_module_loc'] = os.path.normpath(filename)
break
localenv.AlwaysBuild(localenv.AddPostAction(mod_inst, find_module_dir))
elif localenv['PYTHON_INSTALLER'] == 'debian':
install(localenv.Command, 'dummy', pymodule,
'cd %s && $python_cmd setup.py install %s --install-layout=deb --no-compile' % (moddir,extra))
env['python_module_loc'] = '<unspecified>'
elif localenv['PYTHON_INSTALLER'] == 'binary':
install(localenv.Command, 'dummy', pymodule,
'cd %s && $python_cmd setup.py bdist_msi --dist-dir=../..' % moddir +
' --target-version=' + distutils.sysconfig.get_python_version())
env['python_module_loc'] = '<unspecified>'
if localenv['python_package'] == 'full':
install(localenv.RecursiveInstall, pjoin('$inst_sampledir', 'python'),