Skip to content

Commit

Permalink
Two stage download & install process for pip into SPHERAL_PIP_CACHE_D…
Browse files Browse the repository at this point in the history
…IR; System + compiler specific cache directories; Clean targets for pip cache and envs.
  • Loading branch information
mdavis36 committed Nov 13, 2024
1 parent d8f21a2 commit 50afffd
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 11 deletions.
67 changes: 61 additions & 6 deletions cmake/spheral/SpheralPRT.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand Down
5 changes: 0 additions & 5 deletions scripts/spheral-setup-venv.in
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 50afffd

Please sign in to comment.