Require pybind 2.6 from environment for gmxapi Python package extension module.
[alexxy/gromacs.git] / admin / ci-scripts / build-and-test-sample_restraint-2022.sh
1 #!/usr/bin/env bash
2 #
3 # Build and test the sample_restraint package distributed with GROMACS 2022.
4 #
5 # This script is intended to support automated GROMACS testing infrastructure,
6 # and may be removed without notice.
7 #
8 # WARNING: This script assumes OpenMPI mpiexec. Syntax for launch wrappers from
9 # other implementations will need different syntax, and we should get a
10 # MPIRUNNER from the environment, or something.
11
12 # Make sure the script errors if any commands error.
13 set -e
14
15 pushd python_packaging/src
16   # Build and install gmxapi python package from local source.
17   # Note that tool chain may be provided differently across GROMACS versions.
18   if [ "2022" -eq "$GROMACS_MAJOR_VERSION" ]; then
19       GMXTOOLCHAINDIR=$INSTALL_DIR/share/cmake/gromacs \
20           python -m pip install \
21               --no-cache-dir \
22               .
23   # TODO: Get sdist artifact for other gmxapi versions.
24 #    elif [ "2021" -eq "$GROMACS_MAJOR_VERSION" ]; then
25 #      GMXTOOLCHAINDIR=$INSTALL_DIR/share/cmake/gromacs \
26 #          python -m pip install \
27 #              --no-cache-dir \
28 #              --no-deps \
29 #              --no-index \
30 #              dist/gmxapi*
31   else
32       echo "Logic error in GROMACS version handling."
33       exit 1
34   fi
35 popd
36
37 . $INSTALL_DIR/bin/GMXRC
38 pushd python_packaging/sample_restraint
39   mkdir build
40   pushd build
41     # TODO: Update with respect to https://gitlab.com/gromacs/gromacs/-/issues/3133
42     cmake .. \
43       -DPYTHON_EXECUTABLE=`which python` \
44       -DDOWNLOAD_GOOGLETEST=ON \
45       -DGMXAPI_EXTENSION_DOWNLOAD_PYBIND=ON
46     make -j4 tests
47     make test
48     #TODO: Can we get ctest JUnitXML output here?
49
50     make install
51   popd
52
53   python -m pytest $PWD/tests --junitxml=$PLUGIN_TEST_XML --threads=2
54
55   # Note: Multiple pytest processes getting --junitxml output file argument
56   # may cause problems, so we set the option on only one of the launched processes.
57   # See also Multiple Instruction Multiple Data Model for OpenMPI mpirun:
58   # https://www.open-mpi.org/doc/v3.0/man1/mpiexec.1.php
59   PROGRAM=(`which python` -m mpi4py -m pytest \
60           -p no:cacheprovider \
61           $PWD/tests \
62           --threads=1)
63   # shellcheck disable=SC2068
64   if [ -x `which mpiexec` ]; then
65       PYTHONDONTWRITEBYTECODE=1 \
66       mpiexec --allow-run-as-root \
67         -x OMP_NUM_THREADS=1 \
68         --mca opal_warn_on_missing_libcuda 0 \
69         --mca orte_base_help_aggregate 0 \
70         -n 1 ${PROGRAM[@]} --junitxml=$PLUGIN_MPI_TEST_XML : \
71         -n 1 ${PROGRAM[@]}
72   fi
73 popd