From 42a327501ec15e1af82167b9644554049261e0c7 Mon Sep 17 00:00:00 2001 From: Sylvain Tricot Date: Tue, 19 Nov 2019 00:38:08 +0100 Subject: [PATCH] Work on install script Add support for user local install Add support for already existing venv --- src/install.sh | 82 ++++++++++++++++++++++++++++++-------------------- 1 file changed, 50 insertions(+), 32 deletions(-) diff --git a/src/install.sh b/src/install.sh index a0ccf50..ff4741e 100755 --- a/src/install.sh +++ b/src/install.sh @@ -1,6 +1,6 @@ #!/bin/bash -PYTHON_VERSION=python3 +PYTHON=python3 VERSION=$(cat ./msspec/version.py|cut -d\" -f2) DEFAULT_DEST="${HOME}/.local/share" DEFAULT_BIN="${HOME}/.local/bin" @@ -32,9 +32,7 @@ abort_install () { } log_message () { - ${ECHO} "================================================================================" >> ${LOGFILE} ${ECHO} "$1" >> ${LOGFILE} - ${ECHO} "================================================================================" >> ${LOGFILE} } cleanup () { @@ -73,7 +71,7 @@ get_os () { read_yes_no () { PROMPT="$1" DEFAULT="$2" - BYPASS="$3" + #BYPASS="$3" ANSWER="" RESPONSE="" @@ -91,6 +89,8 @@ read_yes_no () { } + + create_folder () { FOLDER="$1" @@ -99,7 +99,7 @@ create_folder () { ERR_PERMS=3 if ! test -d "${FOLDER}" ; then - read_yes_no "The folder \"${FOLDER}\" does not exist. Should I create it" "y" "$BYPASS" + read_yes_no "The folder \"${FOLDER}\" does not exist. Should I create it" "y" #"$BYPASS" case "${ANSWER}" in y) mkdir -p "${FOLDER}" 2>>${LOGFILE} 1>>${LOGFILE} || return $ERR_MKDIR;; @@ -145,7 +145,9 @@ common_install () { wrap () { + log_message "================================================================================" log_message "$2" + log_message "================================================================================" if [ "$DEBUG" = "y" ]; then eval "($1) 2>&1" | tee -a ${LOGFILE} echo ${PIPESTATUS[0]} >${GETOUTFILE} @@ -176,12 +178,6 @@ local_install () { ${ECHO} "" fi - # Create the destination folder - ANSWER="" - test "$BYPASS" = "y" || read -p "Please, type in the base installation folder ["${DEFAULT_DEST}"]: " "ANSWER" - DEST_FOLDER="${ANSWER:-$DEFAULT_DEST}/MsSpec-${VERSION}" - create_folder "${DEST_FOLDER}" || error_exit - export DEST_FOLDER ANSWER="" test "$BYPASS" = "y" || read -p "Please, type in the folder where to place the binary ["${DEFAULT_BIN}"]: " "ANSWER" @@ -189,22 +185,52 @@ local_install () { create_folder "${BIN_FOLDER}" || error_exit export BIN_FOLDER - # create a virtualenv - # check if we are in a virtualenv and exit if so + # If in a virtualenv, ask if we should install inside if [ x"$VIRTUAL_ENV" != x ]; then - ${ECHO} "Installation from a previous virtualenv is not yet supported. Please deactivate it and restart the setup program." >>${LOGFILE} - error_exit + echo "You are running a Python virtual environment" + read_yes_no "Do you wish to install msspec inside ?" "y" + case ${ANSWER} in + y) # get the python version of this venv + v=$(python -V 2>&1 | cut -d" " -f2 | cut -d. -f1) + if [ $v -lt 3 ]; then + log_message "The Python version of this venv is < 3" + error_exit + fi + ;; + n) error_exit + ;; + esac + else + pip_opt="" + read_yes_no "Do you wish to create a virtual environment to install MsSpec inside" "y" + case ${ANSWER} in + y) # Create the destination folder + ANSWER="" + test "$BYPASS" = "y" || \ + read -p "Please, type in the base installation folder ["${DEFAULT_DEST}"]: " "ANSWER" + DEST_FOLDER="${ANSWER:-$DEFAULT_DEST}/MsSpec-${VERSION}" + test -d $DEST_FOLDER && log_message "The folder $DEST_FOLDER already exists." && exit + create_folder "${DEST_FOLDER}" || error_exit + export DEST_FOLDER + wrap "${PYTHON} -m venv --system-site-packages --prompt=\"(msspec-${VERSION}) \" ${DEST_FOLDER}/venv" \ + "Create a Python virtual environment" + . ${DEST_FOLDER}/venv/bin/activate + ;; + n) pip_opt="--user" + esac fi - wrap "virtualenv -v --python=${PYTHON_VERSION} --system-site-packages --prompt=\"(msspec-${VERSION}) \" ${DEST_FOLDER}/venv" \ - "Create a Python virtual environment" - . ${DEST_FOLDER}/venv/bin/activate # install pymsspec - wrap "make install" \ + wrap "make sdist" \ + "Building MsSpec python package" + + wrap "pip install $pip_opt dist/msspec-*.tar.gz" \ "Installing pymsspec python package and its dependencies" # deactivate the virtualenv - deactivate + #if [ x"$pip_opt" = "x" ]; then + # deactivate + #fi # ## move the frontend to the binary folder ##wrap "mkdir -p ${LOCALBIN} && \ @@ -217,7 +243,7 @@ local_install () { #wrap "cp ./uninstall.sh ${DEST}" "Moving the uninstall script" # # installation was a succes so move the logfile to the DEST directory - wrap "cp ${LOGFILE} ${DEST_FOLDER}/msspec_install.log" "Moving the logfile" + #wrap "cp ${LOGFILE} ${DEST_FOLDER}/msspec_install.log" "Moving the logfile" # self-explanatory success_message @@ -241,9 +267,9 @@ update_path () { success_message () { - ${ECHO} "========================================================" - ${ECHO} "MsSpec was successfully installed." - ${ECHO} "========================================================" + log_message "========================================================" + log_message "MsSpec was successfully installed." + log_message "========================================================" } @@ -274,12 +300,6 @@ patience () { -#create_dest_folder -#echo $DEST_FOLDER -#exit - - - while getopts "p:b:yd" option do @@ -300,5 +320,3 @@ done local_install - -