Files
opm-simulators/python/generate-pypi-package.sh
T
Arne Morten Kvarving 4f33fbd598 Merge pull request #6142 from hakonhagland/gen_shared
Allow Dockerfile to generate PyPI package from shared libs
2025-08-22 10:27:15 +02:00

75 lines
2.4 KiB
Bash
Executable File

#!/bin/bash
set -e
VERSION=${1:-"master"}
BUILD_JOBS=${2:-16}
VERSION_TAG=${3:-""}
LIBTYPE=${4:-"static"}
if [ "$LIBTYPE" == "static" ]; then
shared=0
static=1
libext="a"
else
shared=1
static=0
libext="so"
fi
export CMAKE_GENERATOR=Ninja
declare -A python_versions
python_versions[cp38-cp38]=/opt/python/cp38-cp38/bin/python
python_versions[cp39-cp39]=/opt/python/cp39-cp39/bin/python
python_versions[cp310-cp310]=/opt/python/cp310-cp310/bin/python
python_versions[cp311-cp311]=/opt/python/cp311-cp311/bin/python
python_versions[cp312-cp312]=/opt/python/cp312-cp312/bin/python
python_versions[cp313-cp313]=/opt/python/cp313-cp313/bin/python
for python_bin in ${python_versions[*]}
do
${python_bin} -m pip install pip --upgrade
${python_bin} -m pip install wheel setuptools twine pytest-runner auditwheel scikit-build cmake numpy
done
DIR=`pwd`
# Setup opm modules
git clone https://github.com/OPM/opm-common -b $VERSION
git clone https://github.com/OPM/opm-grid -b $VERSION
git clone https://github.com/OPM/opm-simulators -b $VERSION
git clone https://github.com/OPM/opm-utilities
ln -sf opm-utilities/opm-super/CMakeLists.txt CMakeLists.txt
sed -e 's/add_subdirectory(opm-upscaling)//' -e 's/add_dependencies(opmupscaling opmgrid)//g' -i CMakeLists.txt
mkdir -p /tmp/opm/wheelhouse
for tag in ${!python_versions[@]}
do
# Delete the folder if it already exists
if [ -d $tag ]; then
rm -rf $tag
fi
mkdir $tag && pushd $tag
cmake -DPYTHON_EXECUTABLE=${python_versions[$tag]} -DWITH_NATIVE=0 -DBoost_USE_STATIC_LIBS=$static \
-DOPM_ENABLE_PYTHON=ON -DOPM_PYTHON_PACKAGE_VERSION_TAG=${VERSION_TAG} -DBLA_STATIC=$static -DBLAS_LIBRARIES=/usr/lib64/libblas.$libext -DSUITESPARSE_USE_STATIC=$static -DCMAKE_DISABLE_FIND_PACKAGE_QuadMath=1 -DBUILD_SHARED_LIBS=$shared ..
cmake --build . --target opmcommon_python simulators --parallel ${BUILD_JOBS}
# Package opm-common bindings
cd opm-common/python
${python_versions[$tag]} setup.py sdist bdist_wheel --plat-name manylinux_2_28_x86_64 --python-tag $tag
${python_versions[$tag]} -m auditwheel repair dist/*$tag*.whl
cp dist/*$tag*.whl /tmp/opm/wheelhouse
cd ../..
cd opm-simulators/python
${python_versions[$tag]} setup.py sdist bdist_wheel --plat-name manylinux_2_28_x86_64 --python-tag $tag
${python_versions[$tag]} -m auditwheel repair dist/*$tag*.whl
cp dist/*$tag*.whl /tmp/opm/wheelhouse
popd
done