diff --git a/cmake/spheral/SpheralPRT.cmake b/cmake/spheral/SpheralPRT.cmake index e73963965..125da9df0 100644 --- a/cmake/spheral/SpheralPRT.cmake +++ b/cmake/spheral/SpheralPRT.cmake @@ -2,6 +2,19 @@ # Spheral_Python_Runtime_Env #---------------------------------------------------------------------------------------- + +set(SPHERAL_PIP_CACHE_DIR ~/.cache/spheral_pip) +if (DEFINED ENV{SYS_TYPE}) + set(SPHERAL_PIP_CACHE_DIR ${SPHERAL_PIP_CACHE_DIR}/$ENV{SYS_TYPE}) +endif() +set(SPHERAL_PIP_CACHE_DIR ${SPHERAL_PIP_CACHE_DIR}/${CMAKE_CXX_COMPILER_ID}-${CMAKE_CXX_COMPILER_VERSION}) + + +add_custom_target(clean_pip_cache + COMMAND rm -rf ${SPHERAL_PIP_CACHE_DIR} + ) + + function(Spheral_Python_Env target_name) # Define our arguments @@ -16,13 +29,55 @@ function(Spheral_Python_Env target_name) list(APPEND REQUIREMENTS_ARGS ${SPHERAL_ROOT_DIR}/scripts/${_req}) endforeach() - add_custom_target(${target_name} ALL - COMMAND ${Python3_EXECUTABLE} -m venv --system-site-packages ${${target_name}_PREFIX}/.venv; - COMMAND . ${${target_name}_PREFIX}/.venv/bin/activate && - python -m pip install --cache-dir ~/spheral-pip-cache --upgrade pip && - python -m pip install --cache-dir ~/spheral-pip-cache ${REQUIREMENTS_ARGS} - DEPENDS Python3::Python + #TODO: Remove this once blueos3 is no longer supported. + set(SPHERAL_USE_SITE_PACKAGES_OPT ) + if($ENV{SYS_TYPE} STREQUAL "blueos_3_ppc64le_ib_p9") + set(SPHERAL_USE_SITE_PACKAGES_OPT --system-site-packages) + set(PIP_INSTALL_CMD env MPICC=${MPI_C_COMPILER} MPICXX=${MPI_CXX_COMPILER} CC=${CMAKE_C_COMPILER} CXX=${CMAKE_CXX_COMPILER} + python -m pip install + --disable-pip-version-check + --no-build-isolation + -f ${SPHERAL_PIP_CACHE_DIR}) + + add_custom_target(${target_name} ALL + COMMAND ${Python3_EXECUTABLE} -m venv --system-site-packages ${${target_name}_PREFIX}/.venv; + COMMAND . ${${target_name}_PREFIX}/.venv/bin/activate && + + ${PIP_INSTALL_CMD} ${REQUIREMENTS_ARGS} + + DEPENDS Python3::Python + ) + else() + set(PIP_DOWNLOAD_CMD python -m pip download + --disable-pip-version-check + --exists-action i + -d ${SPHERAL_PIP_CACHE_DIR}) + + set(PIP_INSTALL_CMD env MPICC=${MPI_C_COMPILER} MPICXX=${MPI_CXX_COMPILER} CC=${CMAKE_C_COMPILER} CXX=${CMAKE_CXX_COMPILER} + python -m pip install + --disable-pip-version-check + --no-build-isolation + --no-index + -f ${SPHERAL_PIP_CACHE_DIR}) + + add_custom_target(${target_name} ALL + COMMAND ${Python3_EXECUTABLE} -m venv ${${target_name}_PREFIX}/.venv; + COMMAND . ${${target_name}_PREFIX}/.venv/bin/activate && + + ${PIP_DOWNLOAD_CMD} setuptools wheel cython poetry-core && + ${PIP_INSTALL_CMD} setuptools wheel cython poetry-core && + + ${PIP_DOWNLOAD_CMD} ${REQUIREMENTS_ARGS} && + ${PIP_INSTALL_CMD} ${REQUIREMENTS_ARGS} + + DEPENDS Python3::Python + ) + endif() + + add_custom_target(clean_${target_name} + COMMAND rm -rf ${${target_name}_PREFIX} ) + set_property(TARGET ${target_name} PROPERTY EXECUTABLE python) set_property(TARGET ${target_name} PROPERTY ACTIVATE_VENV . ${${target_name}_PREFIX}/.venv/bin/activate) endfunction() diff --git a/scripts/spheral-setup-venv.in b/scripts/spheral-setup-venv.in index b0a7fe548..1ca7cfbae 100644 --- a/scripts/spheral-setup-venv.in +++ b/scripts/spheral-setup-venv.in @@ -7,11 +7,6 @@ cd @CMAKE_INSTALL_PREFIX@/.venv/@SPHERAL_SITE_PACKAGES_PATH@/Spheral cp --symbolic-link @CMAKE_INSTALL_PREFIX@/@SPHERAL_SITE_PACKAGES_PATH@/Spheral/* . > /dev/null 2>&1 cd - > /dev/null -# We need to reconfigure ATS to use our virtual env python otherwise ats will not be able to launch properly. -# echo "Reconfigure ATS executing python to virtual env python..." -# sed -i '2s/.*/XXXXXX/' .venv/bin/ats -# sed -i 's|XXXXXX|\x27\x27\x27exec\x27 @CMAKE_INSTALL_PREFIX@/.venv/bin/python "$0" "$@"|' .venv/bin/ats - echo "Creating spheral symlink to spheral-env script ..." cd @CMAKE_INSTALL_PREFIX@ chmod u+x scripts/spheral-env.sh