Skip to content
Snippets Groups Projects
Commit 8b389d1d authored by Jan Ebert's avatar Jan Ebert
Browse files

Improve bash code

- more modern bash code (e.g. replace backtick expansions with
  `$([...])`)
- handle more paths (e.g. with spaces); this boils down to simply
  quoting every variable
- prefer clearer `${BASH_SOURCE[0]}` over `$BASH_SOURCE`
parent 6ded5a50
No related branches found
No related tags found
No related merge requests found
#!/bin/bash #!/bin/bash
RELATIVE_PATH=`dirname ${BASH_SOURCE}`
ABSOLUTE_PATH=`realpath ${RELATIVE_PATH}`
[[ $0 != $BASH_SOURCE ]] && echo "The activation script must be sourced, otherwise the virtual environment will not work." || ( echo "Vars script must be sourced." && exit 1) ; RELATIVE_PATH="$(dirname "${BASH_SOURCE[0]}")"
ABSOLUTE_PATH="$(realpath "${RELATIVE_PATH}")"
source ${ABSOLUTE_PATH}/config.sh [[ "$0" != "${BASH_SOURCE[0]}" ]] && echo "The activation script must be sourced, otherwise the virtual environment will not work." || ( echo "Vars script must be sourced." && exit 1) ;
source ${ABSOLUTE_PATH}/modules.sh
export PYTHONPATH=`echo ${ENV_DIR}/lib/python*/site-packages`:${PYTHONPATH} source "${ABSOLUTE_PATH}"/config.sh
source "${ABSOLUTE_PATH}"/modules.sh
source ${ENV_DIR}/bin/activate export PYTHONPATH="$(echo "${ENV_DIR}"/lib/python*/site-packages):${PYTHONPATH}"
source "${ENV_DIR}"/bin/activate
## Check if this script is sourced ## Check if this script is sourced
[[ $0 != $BASH_SOURCE ]] && echo "Setting vars" || ( echo "Vars script must be sourced." && exit 1) ; [[ "$0" != "${BASH_SOURCE[0]}" ]] && echo "Setting vars" || ( echo "Vars script must be sourced." && exit 1) ;
## Determine location of this file ## Determine location of this file
RELATIVE_PATH=`dirname ${BASH_SOURCE}` RELATIVE_PATH="$(dirname "${BASH_SOURCE[0]}")"
ABSOLUTE_PATH=`realpath ${RELATIVE_PATH}` ABSOLUTE_PATH="$(realpath "${RELATIVE_PATH}")"
#################################### ####################################
### User Configuration ### User Configuration
export ENV_NAME=`basename $ABSOLUTE_PATH` # Default Name of the venv is the directory that contains this file export ENV_NAME="$(basename "$ABSOLUTE_PATH")" # Default Name of the venv is the directory that contains this file
export ENV_DIR=${ABSOLUTE_PATH}/venv # Default location of this VENV is "./venv" export ENV_DIR="${ABSOLUTE_PATH}"/venv # Default location of this VENV is "./venv"
#!/bin/bash #!/bin/bash
RELATIVE_PATH=`dirname ${BASH_SOURCE}` RELATIVE_PATH="$(dirname "${BASH_SOURCE[0]}")"
ABSOLUTE_PATH=`realpath ${RELATIVE_PATH}` ABSOLUTE_PATH="$(realpath "${RELATIVE_PATH}")"
source ${ABSOLUTE_PATH}/config.sh source "${ABSOLUTE_PATH}"/config.sh
KERNELFILE=${ENV_DIR}/kernel.sh KERNELFILE="${ENV_DIR}"/kernel.sh
echo the name is $ENV_NAME echo the name is "$ENV_NAME"
echo "Setting up the kernel script in the following dir: " ${KERNELFILE} echo "Setting up the kernel script in the following dir: " "${KERNELFILE}"
echo '#!/bin/bash echo '#!/bin/bash
source '"${ABSOLUTE_PATH}"'/activate.sh source "'"${ABSOLUTE_PATH}"'"/activate.sh
exec python -m ipykernel $@' > ${KERNELFILE} exec python -m ipykernel "$@"' > "${KERNELFILE}"
chmod a+x ${KERNELFILE} chmod a+x "${KERNELFILE}"
mkdir -p ~/.local/share/jupyter/kernels/${ENV_NAME} mkdir -p ~/.local/share/jupyter/kernels/"${ENV_NAME}"
echo '{ echo '{
"argv": [ "argv": [
"'"${KERNELFILE}"'", "'"${KERNELFILE}"'",
"-f", "-f",
"{connection_file}" "{connection_file}"
], ],
"display_name": "'${ENV_NAME}'", "display_name": "'"${ENV_NAME}"'",
"language": "python" "language": "python"
}' > ~/.local/share/jupyter/kernels/${ENV_NAME}/kernel.json }' > ~/.local/share/jupyter/kernels/"${ENV_NAME}"/kernel.json
#!/bin/bash #!/bin/bash
RELATIVE_PATH=`dirname ${BASH_SOURCE}`
ABSOLUTE_PATH=`realpath ${RELATIVE_PATH}`
source ${ABSOLUTE_PATH}/config.sh RELATIVE_PATH="$(dirname "${BASH_SOURCE[0]}")"
source ${ABSOLUTE_PATH}/modules.sh ABSOLUTE_PATH="$(realpath "${RELATIVE_PATH}")"
python -m venv --prompt $ENV_NAME --system-site-packages ${ENV_DIR} source "${ABSOLUTE_PATH}"/config.sh
source "${ABSOLUTE_PATH}"/modules.sh
source ${ABSOLUTE_PATH}/activate.sh python -m venv --prompt "$ENV_NAME" --system-site-packages "${ENV_DIR}"
python -m pip install -r ${ABSOLUTE_PATH}/requirements.txt source "${ABSOLUTE_PATH}"/activate.sh
python -m pip install -r "${ABSOLUTE_PATH}"/requirements.txt
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment