diff --git a/CMakeLists.txt b/CMakeLists.txt index 64faac5f..468eecf1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -57,4 +57,3 @@ if (${PROJECT_NAME}_BUILD_TESTING) coverage_evaluate() endif () endif () - diff --git a/cmake/poetry-install.cmake b/cmake/poetry-install.cmake new file mode 100644 index 00000000..5637462f --- /dev/null +++ b/cmake/poetry-install.cmake @@ -0,0 +1,18 @@ +# run 'poetry install' in python folder + +macro(install_poetry) + + # execute 'poetry install' + set(pythonScriptDir "${PROJECT_SOURCE_DIR}/scripts/python") + if (NOT ${PROJECT_NAME}_PYTHON_SETUP) + execute_process( + COMMAND poetry install + WORKING_DIRECTORY "${pythonScriptDir}" + RESULT_VARIABLE result0 + ERROR_VARIABLE errors0 + OUTPUT_VARIABLE outputs0) + + set(${PROJECT_NAME}_PYTHON_SETUP TRUE CACHE BOOL "Python environment is already setup" FORCE) + endif () + +endmacro() diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index fa6bea20..39b916d1 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -15,15 +15,10 @@ set_target_properties(${PROJECT_NAME}_version_header PROPERTIES FOLDER Dependenc set(pythonScriptDir "${PROJECT_SOURCE_DIR}/scripts/python") set(dataModelDir "${PROJECT_SOURCE_DIR}/vendor/hpwh_data_model") set(genCodeDir "${PROJECT_SOURCE_DIR}/src/hpwh_data_model") -#if (NOT ${PROJECT_NAME}_PYTHON_SETUP) -message(STATUS "Installing python packages") -execute_process( - COMMAND poetry install - WORKING_DIRECTORY "${pythonScriptDir}" - RESULT_VARIABLE result0 - ERROR_VARIABLE errors0 - OUTPUT_VARIABLE outputs0 +include(poetry-install) +install_poetry() +execute_process( COMMAND ${CMAKE_COMMAND} -E make_directory "${dataModelDir}" COMMAND ${GIT_EXECUTABLE} submodule update --init "${dataModelDir}" @@ -36,6 +31,7 @@ execute_process( ERROR_VARIABLE errors1 OUTPUT_VARIABLE outputs1) +set(${PROJECT_NAME}_PYTHON_SETUP TRUE CACHE BOOL "Python environment is already setup" FORCE) message("Poetry install success? ${result0} ${errors0} ${outputs0}") message("Update submodule success? ${GIT_SUBMOD_RESULT}") message("Data-model generation success? ${result1} ${errors1} ${outputs1}") diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index b31a7d5e..6bb72677 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -197,12 +197,9 @@ list(REMOVE_DUPLICATES extendedModelNames) cmake_dependent_option(${PROJECT_NAME}_PYTHON_PLOTS "Generate plots using python comparing measured and simulated data" ON "${PROJECT_NAME}_IS_TOP_LEVEL" OFF) -if (${PROJECT_NAME}_PYTHON_PLOTS AND NOT ${PROJECT_NAME}_PYTHON_SETUP) - message(STATUS "Installing python packages") - set(pythonScriptDir "${PROJECT_SOURCE_DIR}/scripts/python") - execute_process(COMMAND poetry install --no-root WORKING_DIRECTORY "${pythonScriptDir}" RESULT_VARIABLE result ERROR_VARIABLE errors OUTPUT_VARIABLE outputs) - message("Poetry success? ${result} ${errors} ${outputs}") - set(${PROJECT_NAME}_PYTHON_SETUP TRUE CACHE BOOL "Python environment is already setup" FORCE) +if (${PROJECT_NAME}_PYTHON_PLOTS) + include(poetry-install) + install_poetry() endif () #Tests for successful runs