From: Paul Bauer Date: Mon, 10 May 2021 11:46:32 +0000 (+0000) Subject: Make python check if modules are available for checksumming X-Git-Url: http://biod.pnpi.spb.ru/gitweb/?a=commitdiff_plain;h=92e6f7027bd02bfbd9018aa8a33adc2f69e2651e;p=alexxy%2Fgromacs.git Make python check if modules are available for checksumming --- diff --git a/cmake/gmxGenerateVersionInfoWithoutGit.cmake b/cmake/gmxGenerateVersionInfoWithoutGit.cmake index 72b85bcc66..568a1cd476 100644 --- a/cmake/gmxGenerateVersionInfoWithoutGit.cmake +++ b/cmake/gmxGenerateVersionInfoWithoutGit.cmake @@ -48,6 +48,7 @@ # DIRECTORIES_TO_CHECKSUM - List of directories to hash # VERSION_CMAKEIN - path to an input template file # VERSION_OUT - path to the output file +# HAVE_FUNCTIONING_PYTHON - Whether the python used can do the checking. # # The following a possible additional definitions # PYTHON_EXECUTABLE - Needed to run checking stage of current tree @@ -118,7 +119,7 @@ if (SOURCE_IS_SOURCE_DISTRIBUTION) # version of GROMACS is in use. set(RELEASE_CHECKSUM_FILE "${PROJECT_SOURCE_DIR}/src/reference_checksum") if(NOT VERSION_STRING_OF_FORK OR "${VERSION_STRING_OF_FORK}" STREQUAL "") - if(EXISTS ${RELEASE_CHECKSUM_FILE} AND PYTHON_EXECUTABLE) + if(EXISTS ${RELEASE_CHECKSUM_FILE} AND HAVE_FULL_FUNCTIONING_PYTHON) file(READ ${RELEASE_CHECKSUM_FILE} GMX_RELEASE_SOURCE_FILE_CHECKSUM) string(STRIP ${GMX_RELEASE_SOURCE_FILE_CHECKSUM} GMX_RELEASE_SOURCE_FILE_CHECKSUM) set(CHECKSUM_RESULT_FILE "${CMAKE_CURRENT_BINARY_DIR}/computed_checksum") @@ -134,7 +135,7 @@ if (SOURCE_IS_SOURCE_DISTRIBUTION) set(GMX_VERSION_STRING_FULL "${GMX_VERSION_STRING_FULL}-MODIFIED") message(STATUS "The source code for this GROMACS installation is different from the officially released version.") endif() - elseif(PYTHON_EXECUTABLE) + elseif(HAVE_FULL_FUNCTIONING_PYTHON) set(GMX_VERSION_STRING_FULL "${GMX_VERSION_STRING_FULL}-UNCHECKED") set(GMX_RELEASE_SOURCE_FILE_CHECKSUM "NoChecksumFile") set(GMX_CURRENT_SOURCE_FILE_CHECKSUM "NoChecksumFile") @@ -143,7 +144,7 @@ if (SOURCE_IS_SOURCE_DISTRIBUTION) set(GMX_VERSION_STRING_FULL "${GMX_VERSION_STRING_FULL}-UNCHECKED") set(GMX_RELEASE_SOURCE_FILE_CHECKSUM "NoPythonAvailable") set(GMX_CURRENT_SOURCE_FILE_CHECKSUM "NoPythonAvailable") - message(STATUS "Could not calculate checksum of source files without Python") + message(STATUS "Could not calculate checksum of source files without functioning Python") endif() endif() else() diff --git a/cmake/gmxVersionInfo.cmake b/cmake/gmxVersionInfo.cmake index 5b96f80335..7ff192a629 100644 --- a/cmake/gmxVersionInfo.cmake +++ b/cmake/gmxVersionInfo.cmake @@ -323,7 +323,7 @@ if (GMX_GIT_VERSION_INFO) endif() include(gmxCustomCommandUtilities) - +include(FindPythonModule) # The first two are also for use outside this file, encapsulating the details # of how to use the generated VersionInfo.cmake. set(VERSION_INFO_CMAKE_FILE ${PROJECT_BINARY_DIR}/VersionInfo.cmake) @@ -365,6 +365,20 @@ string(REPLACE ";" ":" DIRECTORIES_TO_CHECKSUM_STRING "${SET_OF_DIRECTORIES_TO_C # step 1, so they get regenerated only when the static version info # changes. +# Check if we have all necessary python modules available +if (Python3_Interpreter_FOUND) + set(HAVE_FULL_FUNCTIONING_PYTHON Python3_Interpreter_FOUND) + foreach(module argparse hashlib hmac os stat re) # add further modules if necessary + find_python_module(${module} QUIET) + string(TOUPPER ${module} module_upper) + if(NOT PYTHONMODULE_${module_upper}) + message(STATUS + "Python module ${module} not found - disabling checksum validation") + unset(HAVE_FULL_FUNCTIONING_PYTHON) + endif() + endforeach() +endif() + # Configure information known at this time into a partially filled # version info file. set(VERSION_INFO_CMAKEIN_FILE_PARTIAL @@ -405,6 +419,7 @@ else() OUTPUT ${VERSION_INFO_CMAKE_FILE} COMMAND ${CMAKE_COMMAND} -D PYTHON_EXECUTABLE=${PYTHON_EXECUTABLE} + -D HAVE_FULL_FUNCTIONING_PYTHON=${HAVE_FULL_FUNCTIONING_PYTHON} -D PROJECT_VERSION=${GMX_VERSION_STRING} -D PROJECT_SOURCE_DIR=${PROJECT_SOURCE_DIR} -D DIRECTORIES_TO_CHECKSUM=${DIRECTORIES_TO_CHECKSUM_STRING} @@ -435,7 +450,7 @@ set(CHECKSUM_FILE "${PROJECT_SOURCE_DIR}/src/reference_checksum") # not been tampered with. # Note: The RUN_ALWAYS here is to regenerate the hash file only, it does not # mean that the target is run in all builds -if (Python3_Interpreter_FOUND) +if (HAVE_FULL_FUNCTIONING_PYTHON) # We need the full path to the directories after passing it through set(FULL_PATH_DIRECTORIES "") foreach(DIR ${SET_OF_DIRECTORIES_TO_CHECKSUM})