Debian Codegraph @

Tests/Py/Functional/testpywheel.cmake

raw
1 # Test for the Python wheel
2
3 # glob all .whl files in the directory
4 file(GLOB BA_WHEEL_FILES "${BA_WHEEL_DIR}/*.whl")
5 # take the first file if the list is not empty
6 if(BA_WHEEL_FILES)
7 list(GET BA_WHEEL_FILES 0 BA_WHEEL)
8 message(STATUS "BA_WHEEL_DIR = '${BA_WHEEL_DIR}', BA_WHEEL = '${BA_WHEEL}'")
9 else()
10 message(FATAL_ERROR "BornAgain: no wheel files exist in directory '${BA_WHEEL_DIR}'")
11 endif()
12
13 message(STATUS "BornAgain: creating virtual environment at '${BA_VENV_DIR}' to install the Python wheel...")
14 execute_process(
15 COMMAND "${Python3_EXECUTABLE}" -m venv "${BA_VENV_DIR}"
16 RESULT_VARIABLE _result
17 COMMAND_ECHO STDOUT
18 )
19 if(_result)
20 message(FATAL_ERROR "BornAgain: failed to create venv in directory '${BA_VENV_DIR}'")
21 endif()
22
23 # Python executable of the virtual environment
24 if(WIN32)
25 set(VENV_PYTHON "${BA_VENV_DIR}/Scripts/python.exe")
26 else()
27 set(VENV_PYTHON "${BA_VENV_DIR}/bin/python")
28 endif()
29 message(STATUS "BA_VENV_DIR = '${BA_VENV_DIR}', VENV_PYTHON = '${VENV_PYTHON}'")
30
31 message(STATUS "BornAgain: installing the Python wheel '${BA_WHEEL}' in the virtual environment...")
32 execute_process(
33 COMMAND "${VENV_PYTHON}" "-m" pip install "${BA_WHEEL}"
34 RESULT_VARIABLE _result
35 COMMAND_ECHO STDOUT
36 )
37 if(_result)
38 message(FATAL_ERROR "BornAgain: failed to install Python wheel")
39 endif()
40
41 message(STATUS "BornAgain: testing the Python package...")
42 execute_process(
43 COMMAND "${VENV_PYTHON}" "-c" "import bornagain; print(bornagain.deg);"
44 RESULT_VARIABLE _result
45 COMMAND_ECHO STDOUT
46 )
47 if(_result)
48 message(FATAL_ERROR "BornAgain: failed to use BornAgain package")
49 endif()
50
51 # remove the virtual environment
52 file(REMOVE_RECURSE "${BA_VENV_DIR}")