Skip to content
Snippets Groups Projects
Commit 5c872c4f authored by Michael Langguth's avatar Michael Langguth
Browse files

Create a script to set-up the virtual environment inside a TF1.15 singularity containe.

parent 3438ccb4
No related branches found
No related tags found
No related merge requests found
#
# __authors__ = Bing Gong, Michael Langguth
# __date__ = '2021_10_28'
# __last_update__ = '2021_10_28' by Michael Langguth
#
# **************** Description ****************
# This auxiliary script sets up the virtual environment within a singularity container.
# **************** Description ****************
# sanity checks
# check if we are running in a container
if [ -z "${SINGULARITY_NAME}" ]; then
echo "ERROR: install_venv_container.sh must be called within a running singularity container."
exit
fi
# check if directory to virtual environment is parsed
if [[ -z "$1" ]]; then
echo "ERROR: Provide a name to set up the virtual environment."
exit
fi
# check if virtual environment is not already existing
if [ -d "$1" ]; then
echo "ERROR: Target directory of virtual environment ${1} already exists. Chosse another directory path."
exit
fi
# check for requirement-file
if [ ! -d "${BASE_DIR}/requirements_container.txt" ]; then
echo "ERROR: Cannot find requirement-file ${BASE_DIR}/requirements_container.txt to set up virtual environment."
exit
fi
BASE_DIR=`pwd`
VENV_BASE=$1
VENV_NAME="$(dirname "$ENV_SETUP_DIR")"
VENV_DIR=${VENV_BASE}/${VENV_NAME}
# create basic target directory for virtual environment
mkdir "${VENV_BASE}"
# Install virtualenv in this directory
pip install --target="${VENV_BASE}/" virtualenv
# Change into the directory...
cd "${VENV_BASE}" || exit
# .. to set-up virtual environment therein
python -m virtualenv -p /usr/bin/python --system-site-packages "${VENV_NAME}"
# Activate virtual environment and install required packages
echo "Actiavting virtual environment ${ENV_DIR} to install required Python modules..."
source "${VENV_DIR}/bin/activate"
pip install -r "${BASE_DIR}/requirements_container.txt"
# get back to basic directory
cd "${BASE_DIR}" || exit
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment