Files
cantera/interfaces/python_minimal/SConscript
Bryan Weber 951e3a74a5 [Python Minimal] Use setup.cfg configuration
This change provides similar benefits as for the other two Python
distributions. It should allow easier uploading to PyPI and now includes
the README and License files.
2021-11-26 14:56:00 -05:00

84 lines
3.6 KiB
Python

"""Minimal Python Module"""
from os.path import join as pjoin, normpath
from pathlib import Path
from buildutils import *
Import('env', 'build', 'install')
localenv = env.Clone()
make_setup = build(localenv.SubstFile("setup.cfg", "setup.cfg.in"))
# copy scripts from the full Cython module
for script in ["ctml_writer", "ck2cti", "ck2yaml", "cti2yaml", "ctml2yaml"]:
# The actual script
s = build(env.Command(f"cantera/{script}.py",
f"#interfaces/cython/cantera/{script}.py",
Copy("$TARGET", "$SOURCE")))
localenv.Depends(make_setup, s)
build_cmd = ("cd interfaces/python_minimal && "
"$python_cmd_esc setup.py build --build-base=../../build/python")
mod = build(localenv.Command("#build/python/cantera/__init__.py", "setup.cfg",
build_cmd))
env['python_module'] = mod
readme = localenv.Command("README.rst", "#README.rst", Copy("$TARGET", "$SOURCE"))
# The target of this command must match the file listed in setup.cfg.in
license = localenv.Command("LICENSE.txt", "#License.txt",
Copy("$TARGET", "$SOURCE"))
localenv.Depends(license, localenv["license_target"])
localenv.Depends(mod, [make_setup, readme, license])
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 given
if localenv['debian'] and localenv.subst('${python_prefix}') == '/usr/local':
# Installation to /usr/local is the default on Debian-based distributions
extra = ''
elif localenv['OS'] == 'Darwin':
extra = localenv.subst(' --prefix=${python_prefix}')
elif localenv['libdirname'] != 'lib':
# 64-bit RHEL / Fedora etc. or e.g. x32 Gentoo profile
extra = localenv.subst(
' --prefix=${{python_prefix}}'
' --install-lib=${{python_prefix}}/${{libdirname}}/python{}/site-packages'.format(py_version))
else:
extra = '--user'
localenv.AppendENVPath(
'PYTHONUSERBASE',
normpath(localenv.subst('$python_prefix')))
else:
# Install Python module in the default location
extra = ''
if env["stage_dir"]:
# Get the absolute path to the stage directory. If the stage directory is a relative
# path, consider it to be relative to the root of the Cantera source directory,
# which is two directories up from the current working directory of this SConscript
# file.
stage_absolute = Path.cwd().parents[1].joinpath(env["stage_dir"]).resolve()
extra += f" --root={stage_absolute}"
mod_inst = install(localenv.Command, 'dummy', mod,
build_cmd + ' install ' + extra +
' --record=../../build/python-installed-files.txt' +
' --single-version-externally-managed')
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'] = normpath(filename)
break
localenv.AlwaysBuild(localenv.AddPostAction(mod_inst, find_module_dir))
env['install_python_action'] = mod_inst