From eb11a61899a2800d7605b8c4701cbc4bca1ec4e2 Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Sat, 23 Mar 2024 20:22:06 -0400 Subject: [PATCH] Avoid running `pip install -r` on every configure. This saves between 2 - 4 seconds for each reconfigure on my system. --- cmake/PythonUtils.cmake | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/cmake/PythonUtils.cmake b/cmake/PythonUtils.cmake index 249a812150..a2f28b4b57 100644 --- a/cmake/PythonUtils.cmake +++ b/cmake/PythonUtils.cmake @@ -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(