Page MenuHomec4science

SConscript
No OneTemporary

File Metadata

Created
Wed, Apr 24, 04:41

SConscript

# -*- mode:python; coding: utf-8 -*-
# vim: set ft=python:
#
# Copyright (©) 2016-2024 EPFL (École Polytechnique Fédérale de Lausanne),
# Laboratory (LSMS - Laboratoire de Simulation en Mécanique des Solides)
# Copyright (©) 2020-2024 Lucas Frérot
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
from __future__ import print_function
from SCons.Script import Import, Split, Copy, Dir
Import('main_env')
# Pybind11 wrapper
env_pybind = main_env.Clone(SHLIBPREFIX='')
# Remove pedantic warnings
cxx_flags = env_pybind['CXXFLAGS']
try:
del cxx_flags[cxx_flags.index('-pedantic')]
except ValueError:
pass
env_pybind.Tool(pybind11)
pybind_sources = Split("""
tamaas_module.cpp
wrap/core.cpp
wrap/percolation.cpp
wrap/surface.cpp
wrap/model.cpp
wrap/solvers.cpp
wrap/compute.cpp
wrap/mpi.cpp
wrap/materials.cpp
wrap/test_features.cpp
""")
# Setting paths to find libTamaas
env_pybind.AppendUnique(LIBPATH=['../src'])
# Link against a static libTamaas
if env_pybind['build_static_lib']:
env_pybind.PrependUnique(LIBS=['Tamaas']) # keep other libs for link
# Link against a dynamic libTamaas
else:
env_pybind.AppendUnique(RPATH=[
"'$$$$ORIGIN/../../src'", # path to lib in build_dir
"'$$$$ORIGIN/../../..'", # path to lib in install prefix
])
env_pybind['LIBS'] = ['Tamaas'] # discard other libs for link
# Building the pybind library
tamaas_wrap = env_pybind.Pybind11Module(
target='tamaas/_tamaas',
source=pybind_sources,
)
# For some reason link happens too early
Import('libTamaas')
env_pybind.Depends(tamaas_wrap, libTamaas)
# Copying the __init__.py file with extra python classes
copy_env = env_pybind.Clone()
# Copying additional python files
python_files = """
__main__.py
compute.py
utils.py
dumpers/__init__.py
dumpers/_helper.py
nonlinear_solvers/__init__.py
materials/__init__.py
""".split()
targets = [tamaas_wrap]
targets += [
copy_env.Command(copy_env.File(f, 'tamaas'),
copy_env.File(f, '#python/tamaas'),
Copy("$TARGET", "$SOURCE"))
for f in python_files
]
dist_files = """
MANIFEST.in
pypi.md
pyproject.toml
""".split()
targets += [
copy_env.Command(copy_env.File(f, ''),
copy_env.File(f, '#python'),
Copy("$TARGET", "$SOURCE"))
for f in dist_files
]
subst_env = env_pybind.Clone(
SUBST_DICT={
'@version@': '$version',
'@authors@': str(copy_env['authors']),
'@author_list@': ', '.join(copy_env['authors']),
'@email@': '$email',
'@description@': '$description',
'@copyright@': '$copyright',
'@maintainer@': '$maintainer',
'@license@': '$license',
}
)
subst_env.Tool('textfile')
targets.append(subst_env.Substfile('tamaas/__init__.py.in'))
targets.append(subst_env.Substfile('setup.cfg.in'))
# Defining alias for python builds
main_env.Alias('build-python', targets)
# Checking if we can use pip to install (more convenient for end-user)
install_env = main_env.Clone()
conf = Configure(install_env,
custom_tests={'CheckPythonModule': CheckPythonModule})
has_pip = conf.CheckPythonModule('pip')
install_env = conf.Finish()
# Current build directory
install_env['PYDIR'] = Dir('.')
# Setting command line for installation
install_env['PYINSTALLCOM'] = '${py_exec} -m pip install -U $PYOPTIONS .'
install_env['PYDEVELOPCOM'] = \
'${py_exec} -m pip install $PYOPTIONS -e .[all]'
# Options passed to pip
PYOPTIONS = ['${"" if verbose else "-q"}'] \
+ Split(install_env.get('PIPFLAGS'))
# Specify install targets
python_install = install_env.Command(
'.python_install_phony',
targets, install_env['PYINSTALLCOM'],
PYOPTIONS=['--prefix', '${prefix}'] + PYOPTIONS,
chdir=install_env['PYDIR'])
python_install_dev = install_env.Command(
'.python_install_local_phony',
targets, install_env['PYDEVELOPCOM'],
# Temporary fix for https://github.com/pypa/pip/issues/7953
PYOPTIONS=PYOPTIONS,
chdir=install_env['PYDIR'])
# Defining aliases
if has_pip:
main_env.Alias('install-python', python_install)
main_env.Alias('dev', python_install_dev)
# Define dummy commands if pip not installed
else:
dummy_command(main_env, 'dev', 'Command "dev" does not do anything '
'without pip installed')
dummy_command(main_env, 'install-python', 'Cannot install python '
'package without pip installed')

Event Timeline