Skip to content

Commit

Permalink
Prevent multiple poetry installs.
Browse files Browse the repository at this point in the history
  • Loading branch information
spahrenk committed Oct 30, 2024
1 parent 2c6a7cc commit c83dd55
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 15 deletions.
1 change: 0 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,3 @@ if (${PROJECT_NAME}_BUILD_TESTING)
coverage_evaluate()
endif ()
endif ()

18 changes: 18 additions & 0 deletions cmake/poetry-install.cmake
Original file line number Diff line number Diff line change
@@ -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()
12 changes: 4 additions & 8 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand All @@ -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}")
Expand Down
9 changes: 3 additions & 6 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c83dd55

Please sign in to comment.