Switch Cython and python interfaces to setuptools

Replace distutils with setuptools in the Cython and python_minimal
interfaces. Add console_scripts option to generate OS specific scripts to run
ck2cti, mixmaster, and ctml_writer

Remove script files that are obsoleted by console_scripts from
setuptools. Remove installation of the script modules from SConstruct.

Fix Python installers so that when a prefix directory is specified on the
command line, setuptools doesn't throw an error. The setuptools documentation at
[1] prefers setting PYTHONUSERBASE rather than PYTHONPATH. Use normpath to avoid
bugs in setuptools on Windows [2].  Specify an empty "--prefix" if the compiler
is clang to fix a bug with Homebrew Python on Mac OSX [3].

[1]: https://pythonhosted.org/setuptools/easy_install.html#custom-installation-locations
[2]: http://stackoverflow.com/q/31629398
[3]: https://github.com/Homebrew/homebrew-python/issues/187
This commit is contained in:
Bryan W. Weber
2015-08-02 14:08:55 -04:00
committed by Ray Speth
parent 5f8bd40c0d
commit b979cea3d2
9 changed files with 52 additions and 75 deletions

View File

@@ -5,8 +5,6 @@ Import('env', 'build', 'install')
localenv = env.Clone()
script_ext = '.py' if os.name == 'nt' else ''
make_setup = build(localenv.SubstFile('setup.py', 'setup.py.in'))
# copy scripts from the full Cython module
@@ -15,16 +13,7 @@ for script in ['ctml_writer', 'ck2cti']:
s = build(env.Command('cantera/%s.py' % script,
'#interfaces/cython/cantera/%s.py' % script,
Copy('$TARGET', '$SOURCE')))
# thin wrapper
w = build(env.Command('scripts/%s%s' % (script, script_ext),
'#interfaces/cython/scripts/%s.py.in' % script,
Copy('$TARGET', '$SOURCE')))
localenv.Depends(make_setup, s)
localenv.Depends(make_setup, w)
# Name used in setup.py
localenv['py_%s' % script] = repr('scripts/%s%s' % (script, script_ext))
localenv['py_%s' % script] = repr('scripts/%s%s' % (script, script_ext))
build_cmd = ('cd interfaces/python_minimal &&'
' $python_cmd_esc setup.py build --build-lib=../../build/python2')
@@ -38,23 +27,33 @@ if localenv['PYTHON_INSTALLER'] == 'direct':
if localenv['python_prefix'] == 'USER':
# Install to the OS-dependent user site-packages directory
extra = '--user'
if localenv['OS'] == 'Darwin':
extra += ' --prefix=""'
elif localenv['python_prefix']:
# A specific location for the Cantera python module has been specified
extra = '--prefix="%s"' % localenv['python_prefix']
# A specific location for the Cantera python module has been given
extra = '--user'
if localenv['OS'] == 'Darwin':
extra += ' --prefix=""'
localenv.AppendENVPath(
'PYTHONUSERBASE',
normpath(localenv.subst('$python_prefix'))
)
else:
# Install Python module in the default location
extra = ''
mod_inst = install(localenv.Command, 'dummy', mod,
build_cmd + ' install %s' % extra +
' --record ../../build/python2-installed-files.txt')
' --record=../../build/python2-installed-files.txt' +
' --single-version-externally-managed')
global_env = env
def find_module_dir(target, source, env):
check = pjoin('cantera','__init__.py')
check = pjoin('cantera', '__init__.py')
for filename in open('build/python2-installed-files.txt').readlines():
filename = filename.strip()
if filename.endswith(check):
filename = filename.replace(check,'')
global_env['python_module_loc'] = os.path.normpath(filename)
filename = filename.replace(check, '')
global_env['python_module_loc'] = normpath(filename)
break
localenv.AlwaysBuild(localenv.AddPostAction(mod_inst, find_module_dir))
env['install_python2_action'] = mod_inst

View File

@@ -1,4 +1,4 @@
from distutils.core import setup
from setuptools import setup
setup(name="Cantera (minimal)",
version="@cantera_version@",
@@ -8,5 +8,10 @@ setup(name="Cantera (minimal)",
author_email="speth@mit.edu",
url="http://www.cantera.org",
packages = ['cantera'],
scripts=[@py_ctml_writer@,
@py_ck2cti@])
entry_points={
'console_scripts': [
'ck2cti=cantera.ck2cti:script_entry_point',
'ctml_writer=cantera.ctml_writer:main',
],
},
)