diff --git a/SConstruct b/SConstruct index f5a1b631f..60a16ca77 100644 --- a/SConstruct +++ b/SConstruct @@ -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 """ diff --git a/interfaces/cython/SConscript b/interfaces/cython/SConscript index 911c6ead5..e07ea2888 100644 --- a/interfaces/cython/SConscript +++ b/interfaces/cython/SConscript @@ -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] = '' 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] = '' libDirs = ('../../build/lib', localenv['sundials_libdir'], diff --git a/platform/posix/SConscript b/platform/posix/SConscript index def48a3f5..f12c0aa77 100644 --- a/platform/posix/SConscript +++ b/platform/posix/SConscript @@ -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' diff --git a/platform/posix/setup_cantera.in b/platform/posix/setup_cantera.in index 77ba64799..745e84887 100644 --- a/platform/posix/setup_cantera.in +++ b/platform/posix/setup_cantera.in @@ -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 diff --git a/site_scons/buildutils.py b/site_scons/buildutils.py index 60fe1bf17..b091aa67b 100644 --- a/site_scons/buildutils.py +++ b/site_scons/buildutils.py @@ -13,6 +13,7 @@ import itertools import SCons.Errors from distutils.version import LooseVersion +import distutils.sysconfig class DefineDict(object): """ diff --git a/src/python/SConscript b/src/python/SConscript index 2544a71ad..f876f706e 100644 --- a/src/python/SConscript +++ b/src/python/SConscript @@ -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'] = '' 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'] = '' if localenv['python_package'] == 'full': install(localenv.RecursiveInstall, pjoin('$inst_sampledir', 'python'),