# Test for the Python wheel # glob all .whl files in the directory file(GLOB BA_WHEEL_FILES "${BA_WHEEL_DIR}/*.whl") # take the first file if the list is not empty if(BA_WHEEL_FILES) list(GET BA_WHEEL_FILES 0 BA_WHEEL) message(STATUS "BA_WHEEL_DIR = '${BA_WHEEL_DIR}', BA_WHEEL = '${BA_WHEEL}'") else() message(FATAL_ERROR "BornAgain: no wheel files exist in directory '${BA_WHEEL_DIR}'") endif() message(STATUS "BornAgain: creating virtual environment at '${BA_VENV_DIR}' to install the Python wheel...") execute_process( COMMAND "${Python3_EXECUTABLE}" -m venv "${BA_VENV_DIR}" RESULT_VARIABLE _result COMMAND_ECHO STDOUT ) if(_result) message(FATAL_ERROR "BornAgain: failed to create venv in directory '${BA_VENV_DIR}'") endif() # Python executable of the virtual environment if(WIN32) set(VENV_PYTHON "${BA_VENV_DIR}/Scripts/python.exe") else() set(VENV_PYTHON "${BA_VENV_DIR}/bin/python") endif() message(STATUS "BA_VENV_DIR = '${BA_VENV_DIR}', VENV_PYTHON = '${VENV_PYTHON}'") message(STATUS "BornAgain: installing the Python wheel '${BA_WHEEL}' in the virtual environment...") execute_process( COMMAND "${VENV_PYTHON}" "-m" pip install "${BA_WHEEL}" RESULT_VARIABLE _result COMMAND_ECHO STDOUT ) if(_result) message(FATAL_ERROR "BornAgain: failed to install Python wheel") endif() message(STATUS "BornAgain: testing the Python package...") execute_process( COMMAND "${VENV_PYTHON}" "-c" "import bornagain; print(bornagain.deg);" RESULT_VARIABLE _result COMMAND_ECHO STDOUT ) if(_result) message(FATAL_ERROR "BornAgain: failed to use BornAgain package") endif() # remove the virtual environment file(REMOVE_RECURSE "${BA_VENV_DIR}")