Skip to content

Commit

Permalink
Merge pull request #1575 from Hoikas/avoid_redundant_pip_install
Browse files Browse the repository at this point in the history
Avoid running `pip install -r` on every configure.
  • Loading branch information
Hoikas authored Mar 25, 2024
2 parents 70c9c0e + eb11a61 commit 146d1e5
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions cmake/PythonUtils.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,22 @@ function(python_test_modules)
endif()

if(_ptm_REQUIREMENTS_FILE)
message(STATUS "Installing Python modules from: ${_ptm_REQUIREMENTS_FILE}")
execute_process(
COMMAND "${Python3_EXECUTABLE}" -m pip install -r "${_ptm_REQUIREMENTS_FILE}"
RESULT_VARIABLE RETURNCODE
OUTPUT_QUIET ERROR_QUIET
)
# Optimization: hash the requirements file and store it on success
# Then, we can avoid running expensive install operations on reconfigure.
file(SHA512 "${_ptm_REQUIREMENTS_FILE}" _REQUIREMENTS_FILE_HASH)
if(NOT _REQUIREMENTS_FILE_HASH IN_LIST _PLASMA_PIP_REQUIREMENTS_HASHES)
message(STATUS "Installing Python modules from: ${_ptm_REQUIREMENTS_FILE}")
execute_process(
COMMAND "${Python3_EXECUTABLE}" -m pip install -r "${_ptm_REQUIREMENTS_FILE}"
RESULT_VARIABLE RETURNCODE
OUTPUT_QUIET ERROR_QUIET
)
if(RETURNCODE EQUAL 0)
set(_PLASMA_PIP_REQUIREMENTS_HASHES "${_PLASMA_PIP_REQUIREMENTS_HASHES}${_REQUIREMENTS_FILE_HASH};" CACHE INTERNAL "")
endif()
else()
message(STATUS "Already installed Python modules from: ${_ptm_REQUIREMENTS_FILE}")
endif()
else()
message(STATUS "Installing Python modules: ${_ptm_MODULES}")
execute_process(
Expand Down

0 comments on commit 146d1e5

Please sign in to comment.