From 8b91c6ca12b6443577fe5adc02d27abb0c5f4235 Mon Sep 17 00:00:00 2001 From: ptaylor Date: Mon, 26 Feb 2024 12:44:22 -0800 Subject: [PATCH] Add python.install template, update python.build.editable template to call it with --editable flag --- .../bin/tmpl/python.build.editable.tmpl.sh | 83 +------------ .../bin/tmpl/python.install.tmpl.sh | 113 ++++++++++++++++++ 2 files changed, 114 insertions(+), 82 deletions(-) create mode 100755 features/src/rapids-build-utils/opt/rapids-build-utils/bin/tmpl/python.install.tmpl.sh diff --git a/features/src/rapids-build-utils/opt/rapids-build-utils/bin/tmpl/python.build.editable.tmpl.sh b/features/src/rapids-build-utils/opt/rapids-build-utils/bin/tmpl/python.build.editable.tmpl.sh index af23f4bf..2171d4a9 100755 --- a/features/src/rapids-build-utils/opt/rapids-build-utils/bin/tmpl/python.build.editable.tmpl.sh +++ b/features/src/rapids-build-utils/opt/rapids-build-utils/bin/tmpl/python.build.editable.tmpl.sh @@ -15,88 +15,7 @@ . rapids-generate-docstring; build_${PY_LIB}_python_editable() { - local -; - set -euo pipefail; - - eval "$(_parse_args "$@" <&0)"; - - local py_lib="${PY_LIB}"; - local py_src="${PY_SRC}"; - - if [[ ! -d "${py_src}" ]]; then - exit 1; - fi - - eval "$( \ - PARALLEL_LEVEL=${PARALLEL_LEVEL:-$(nproc)} \ - rapids-get-num-archs-jobs-and-load "$@" \ - )"; - - # shellcheck disable=SC1091 - . devcontainer-utils-debug-output 'rapids_build_utils_debug' 'build-all build-${NAME} build-${PY_LIB}-python build-${PY_LIB}-python-editable'; - - local -a cmake_args_=( - ${PY_CMAKE_ARGS} - ${CMAKE_ARGS:-} - ${CPP_DEPS} - ${CPP_ARGS} - ${v:+--log-level=VERBOSE} - ); - - local -a cmake_args="( - ${cmake_args_+"${cmake_args_[*]@Q}"} - $(rapids-select-cmake-args "${ARGS[@]}") - )"; - - if test -n "${v}"; then - ninja_args+=("-v"); - fi - - if test -n "${n_jobs}"; then - ninja_args+=("-j${n_jobs}"); - fi - - if test -n "${n_load}"; then - ninja_args+=("-l${n_load}"); - fi - - local -a pip_args_=(${PIP_INSTALL_ARGS}); - local -a pip_args="( - ${pip_args_+"${pip_args_[*]@Q}"} - $(rapids-select-pip-wheel-args "${ARGS[@]}") - )"; - - if rapids-python-uses-scikit-build-core "${py_src}"; then - pip_args+=(-C "build-dir=$(rapids-get-cmake-build-dir -- "${py_src}" "${cmake_args[@]}")"); - else - export SETUPTOOLS_ENABLE_FEATURES=legacy-editable; - fi - - pip_args+=("--no-build-isolation"); - pip_args+=("--no-deps"); - pip_args+=("--editable"); - pip_args+=("${py_src}"); - - cmake_args+=("-DCMAKE_INSTALL_RPATH_USE_LINK_PATH=ON"); - - trap "rm -rf '${py_src}/${py_lib//"-"/"_"}.egg-info'" EXIT; - - time ( - export ${PY_ENV} PATH="$PATH"; - - local cudaflags="${CUDAFLAGS:+$CUDAFLAGS }-t=${n_arch}"; - local nvcc_append_flags="${NVCC_APPEND_FLAGS:+$NVCC_APPEND_FLAGS }-t=${n_arch}"; - - CUDAFLAGS="${cudaflags}" \ - CMAKE_GENERATOR="Ninja" \ - PARALLEL_LEVEL="${n_jobs}" \ - CMAKE_ARGS="${cmake_args[*]}" \ - SKBUILD_BUILD_OPTIONS="${ninja_args[*]}" \ - NVCC_APPEND_FLAGS="${nvcc_append_flags}" \ - python -m pip install "${pip_args[@]}" \ - ; - { set +x; } 2>/dev/null; echo -n "${py_lib} install time:"; - ) 2>&1; + install-${PY_LIB}-python --no-build-isolation --no-deps --editable "${PY_SRC}" "$@" <&0; } build_${PY_LIB}_python_editable "$@" <&0; diff --git a/features/src/rapids-build-utils/opt/rapids-build-utils/bin/tmpl/python.install.tmpl.sh b/features/src/rapids-build-utils/opt/rapids-build-utils/bin/tmpl/python.install.tmpl.sh new file mode 100755 index 00000000..bb140fbb --- /dev/null +++ b/features/src/rapids-build-utils/opt/rapids-build-utils/bin/tmpl/python.install.tmpl.sh @@ -0,0 +1,113 @@ +#!/usr/bin/env bash + +# Usage: +# install-${PY_LIB}-python [OPTION]... +# +# Install ${PY_LIB}. +# +# @_include_value_options rapids-get-num-archs-jobs-and-load -h; +# @_include_cmake_options; +# @_include_pip_install_options; +# @_include_pip_package_index_options; +# @_include_pip_general_options; + +# shellcheck disable=SC1091 +. rapids-generate-docstring; + +install_${PY_LIB}_python() { + local -; + set -euo pipefail; + + eval "$( \ + PARALLEL_LEVEL=${PARALLEL_LEVEL:-$(nproc)} \ + rapids-get-num-archs-jobs-and-load --archs 1 "$@" \ + )"; + + local py_lib="${PY_LIB}"; + + local -a cmake_args_="(${CMAKE_ARGS:-})"; + cmake_args_+=(${CPP_CMAKE_ARGS}); + + local -a pip_args_=(${PIP_INSTALL_ARGS}); + + eval "$(_parse_args --take '-G -e,--editable -v,--verbose' "$@" "${cmake_args_[@]}" "${pip_args_[@]}" <&0)"; + + if [[ ! -d "${PY_SRC}" ]]; then + echo "install-${PY_LIB}-python: cannot access '${PY_SRC}': No such directory" >&2; + exit 1; + fi + + # shellcheck disable=SC1091 + . devcontainer-utils-debug-output 'rapids_build_utils_debug' 'build-all build-${NAME} build-${PY_LIB}-python build-${PY_LIB}-python-editable install-all install-${NAME} install-${PY_LIB}-python'; + + local -a cmake_args="( + -G \"${G:-Ninja}\" + ${cmake_args_[*]@Q} + ${CPP_DEPS} + ${v:+--log-level=VERBOSE} + $(rapids-select-cmake-args "$@") + )"; + + if test -n "${v}"; then + ninja_args+=("-v"); + fi + + if test -n "${n_jobs}"; then + ninja_args+=("-j${n_jobs}"); + fi + + if test -n "${n_load}"; then + ninja_args+=("-l${n_load}"); + fi + + local -a pip_args="( + ${pip_args_+"${pip_args_[*]@Q}"} + $(rapids-select-pip-install-args "$@") + )"; + + if rapids-python-uses-scikit-build-core "${PY_SRC}"; then + pip_args+=(-C "build-dir=$(rapids-maybe-clean-build-dir "${cmake_args[@]}" -- "${PY_SRC}")"); + elif test -n "${editable:-}"; then + export SETUPTOOLS_ENABLE_FEATURES=legacy-editable; + cmake_args+=("-DCMAKE_INSTALL_RPATH_USE_LINK_PATH=ON"); + fi + + # Put --editable at the end of pip_args + if test ${#editable[@]} -gt 0; then + local i; + local n=1; + test -n "${editable:-}" && n=2; + for ((i=0; i < ${#pip_args}; i+=1)); do + case "${pip_args[${i}]}" in + -e|--editable) + pip_args=("${pip_args[@]:0:$i}" "${pip_args[@]:$((i + n))}"); + break; + ;; + esac + done + pip_args+=(--editable "${editable:-${PY_SRC}}"); + else + pip_args+=("${PY_SRC}"); + fi + + trap "rm -rf '${PY_SRC}/${py_lib//"-"/"_"}.egg-info'" EXIT; + + time ( + export ${PY_ENV} PATH="$PATH"; + + local cudaflags="${CUDAFLAGS:+$CUDAFLAGS }-t=${n_arch}"; + local nvcc_append_flags="${NVCC_APPEND_FLAGS:+$NVCC_APPEND_FLAGS }-t=${n_arch}"; + + CUDAFLAGS="${cudaflags}" \ + CMAKE_GENERATOR="${G:-Ninja}" \ + PARALLEL_LEVEL="${n_jobs}" \ + CMAKE_ARGS="${cmake_args[*]}" \ + SKBUILD_BUILD_OPTIONS="${ninja_args[*]}" \ + NVCC_APPEND_FLAGS="${nvcc_append_flags}" \ + python -m pip install "${pip_args[@]}" \ + ; + { set +x; } 2>/dev/null; echo -n "${PY_LIB} install time:"; + ) 2>&1; +} + +install_${PY_LIB}_python "$@" <&0;