Files
opm-common/python/setup.py.in

118 lines
3.4 KiB
Python
Raw Normal View History

2019-06-27 14:08:22 +02:00
from setuptools import setup, find_packages
from setuptools import Extension
from setuptools.command.build_ext import build_ext
import sys
import setuptools
import glob
import os
import re
2019-08-09 13:02:04 +02:00
import subprocess
try:
from importlib.machinery import EXTENSION_SUFFIXES
suffix = EXTENSION_SUFFIXES[0]
except ImportError:
suffix = ".so"
setupdir = os.path.dirname(__file__)
if setupdir != '':
os.chdir( setupdir )
2019-08-09 13:02:04 +02:00
Use C++ everywhere and skip using a custom build_ext subclass. Somehow using a custom build_ext subclass always triggered a failing rebuild when testing: /usr/lib/ccache/g++-10 -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-z,relro -g -fwrapv -O2 -Wl,-z,relro -g -fwrapv -O2 -g -ffile-prefix-map=/build/python3.9-RNBry6/python3.9-3.9.2=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 build/temp.linux-x86_64-3.9/cxx/builtin_pybind11.o build/temp.linux-x86_64-3.9/cxx/connection.o build/temp.linux-x86_64-3.9/cxx/converters.o build/temp.linux-x86_64-3.9/cxx/deck.o build/temp.linux-x86_64-3.9/cxx/deck_keyword.o build/temp.linux-x86_64-3.9/cxx/eclipse_config.o build/temp.linux-x86_64-3.9/cxx/eclipse_grid.o build/temp.linux-x86_64-3.9/cxx/eclipse_io.o build/temp.linux-x86_64-3.9/cxx/eclipse_state.o build/temp.linux-x86_64-3.9/cxx/emodel_util.o build/temp.linux-x86_64-3.9/cxx/export.o build/temp.linux-x86_64-3.9/cxx/field_props.o build/temp.linux-x86_64-3.9/cxx/group.o build/temp.linux-x86_64-3.9/cxx/log.o build/temp.linux-x86_64-3.9/cxx/parsecontext.o build/temp.linux-x86_64-3.9/cxx/parser.o build/temp.linux-x86_64-3.9/cxx/schedule.o build/temp.linux-x86_64-3.9/cxx/summary_state.o build/temp.linux-x86_64-3.9/cxx/table_manager.o build/temp.linux-x86_64-3.9/cxx/unit_system.o build/temp.linux-x86_64-3.9/cxx/well.o -lopmcommon -lboost_system -lstdc++fs -o build/lib.linux-x86_64-3.9/opm/libopmcommon_python.cpython-39-x86_64-linux-gnu.so -fopenmp /usr/lib/x86_64-linux-gnu/libfmt.so.7.1.3 error: can't copy 'build/lib.linux-x86_64-3.9/opm/libopmcommon_python.cpython-39-x86_64-linux-gnu.so': doesn't exist or not a regular file Therefore we resort to only setting the CC and CXX variables to the C++ compiler. Note that one cannot use "ccache c++" for CXX. With the default build_ext the problem vanishes.
2022-02-04 10:07:05 +01:00
cc = "@CMAKE_CXX_COMPILER@"
# setuptools will use the first path as the linker.
# This should not be ccache as this will fail.
# CXX is used for linking and CC for compilation
os.environ['CXX'] = cc
2019-08-09 13:02:04 +02:00
try:
2019-09-17 14:16:55 +02:00
subprocess.call(['ccache', '--version'])
os.environ['CC'] = 'ccache {}'.format(cc)
print("Using 'ccache {}' as compiler".format(cc))
2019-08-09 13:02:04 +02:00
except OSError as e:
os.environ['CC'] = cc
2019-09-17 14:16:55 +02:00
print('\nNOTE: please install ccache for faster compilation of python bindings.\n')
2019-06-27 14:08:22 +02:00
# This is very hacky but so is the entire setup.py buildsystem.
output=subprocess.check_output([cc, "--version"])
libs=['opmcommon', 'boost_system']
output=str(output)
if output.find('Free Software Foundation'):
libs.append('stdc++fs')
2019-06-27 14:08:22 +02:00
if 'build' in sys.argv:
2019-09-17 14:16:55 +02:00
if not 'build_ext' in sys.argv:
raise TypeError("Missing option 'build_ext'.")
2019-06-27 14:08:22 +02:00
ext_modules = [
Extension(
'opm.libopmcommon_python',
2019-06-27 14:08:22 +02:00
[
2019-10-11 16:29:09 +02:00
'cxx/unit_system.cpp',
2019-06-27 14:08:22 +02:00
'cxx/connection.cpp',
2019-10-30 22:34:37 +01:00
'cxx/converters.cpp',
2019-06-27 14:08:22 +02:00
'cxx/deck.cpp',
'cxx/deck_keyword.cpp',
'cxx/eclipse_io.cpp',
'cxx/field_props.cpp',
2019-06-27 14:08:22 +02:00
'cxx/eclipse_config.cpp',
'cxx/eclipse_grid.cpp',
'cxx/eclipse_state.cpp',
'cxx/group.cpp',
2019-09-16 18:33:50 +02:00
'cxx/log.cpp',
'cxx/parsecontext.cpp',
2019-06-27 14:08:22 +02:00
'cxx/parser.cpp',
'cxx/schedule.cpp',
2019-12-27 10:08:46 +01:00
'cxx/summary_state.cpp',
2019-06-27 14:08:22 +02:00
'cxx/table_manager.cpp',
'cxx/well.cpp',
2021-04-11 09:11:35 +02:00
'cxx/emodel_util.cpp',
'cxx/builtin_pybind11.cpp',
'cxx/export.cpp'
2019-06-27 14:08:22 +02:00
],
libraries=libs,
2019-06-27 14:08:22 +02:00
language='c++',
undef_macros=["NDEBUG"],
include_dirs=[@SETUP_PY_INCLUDE_DIRS@],
extra_compile_args=[@SETUP_PY_FLAGS@],
extra_link_args=[@SETUP_PY_LINKAGE@]
2019-10-26 17:33:43 +02:00
)
2019-06-27 14:08:22 +02:00
]
with open("README.md", "r") as fh:
long_description = fh.read()
2019-06-27 14:08:22 +02:00
setup(
name='opm',
version = '@opm-common_VERSION@' + '@opm-common_PYTHON_PACKAGE_VERSION@',
2020-06-16 12:58:45 +02:00
url='http://www.opm-project.org',
author='The Open Porous Media Project',
author_email='opmuser@gmail.com',
description='OPM-Common Python bindings',
long_description=long_description,
long_description_content_type="text/markdown",
2019-06-27 14:08:22 +02:00
packages=[
'opm',
2019-08-23 10:25:54 +02:00
'opm.io',
'opm.io.deck',
'opm.io.ecl_state',
2019-08-23 11:44:41 +02:00
'opm.io.parser',
'opm.io.schedule',
2019-10-26 17:33:43 +02:00
'opm.io.ecl',
2021-04-11 09:11:35 +02:00
'opm.tools',
'opm.util'
2019-06-27 14:08:22 +02:00
],
ext_modules=ext_modules,
include_package_data=True,
2019-06-27 14:08:22 +02:00
license='Open Source',
zip_safe=False,
test_suite='tests',
2019-06-27 14:08:22 +02:00
setup_requires=["pytest-runner", 'setuptools_scm'],
python_requires='>=3.5',
classifiers=[
"Programming Language :: Python :: 3",
"License :: OSI Approved :: GNU General Public License v3 (GPLv3)",
],
2019-06-27 14:08:22 +02:00
)