From 6dfbb8f65c0c217981ef95b51b3f0220969cfc6c Mon Sep 17 00:00:00 2001 From: RodrigoSobral2000 Date: Fri, 20 Sep 2024 17:06:32 +0200 Subject: [PATCH] swancustomenvs: Install ipykernel with requirements Install requirements at the same time as the remaining requirements for better performance --- .../scripts/builders/accpy.sh | 7 ++----- .../scripts/builders/mamba.sh | 18 +++++------------- .../scripts/builders/venv.sh | 7 ++----- 3 files changed, 9 insertions(+), 23 deletions(-) diff --git a/SwanCustomEnvironments/swancustomenvironments/scripts/builders/accpy.sh b/SwanCustomEnvironments/swancustomenvironments/scripts/builders/accpy.sh index eac097d0..c7d6b008 100644 --- a/SwanCustomEnvironments/swancustomenvironments/scripts/builders/accpy.sh +++ b/SwanCustomEnvironments/swancustomenvironments/scripts/builders/accpy.sh @@ -9,9 +9,6 @@ _log "Setting up the environment..." ACTIVATE_ENV_CMD="source ${ENV_PATH}/bin/activate" eval "${ACTIVATE_ENV_CMD}" -# Install packages in the environment +# Install packages in the environment and the same ipykernel that the Jupyter server uses _log "Installing packages from ${REQ_PATH}..." -pip install -r "${REQ_PATH}" | tee -a ${LOG_FILE} - -# Install the same ipykernel that the Jupyter server uses -pip install ipykernel==${IPYKERNEL_VERSION} | tee -a ${LOG_FILE} +pip install -r "${REQ_PATH}" "ipykernel==${IPYKERNEL_VERSION}" | tee -a ${LOG_FILE} diff --git a/SwanCustomEnvironments/swancustomenvironments/scripts/builders/mamba.sh b/SwanCustomEnvironments/swancustomenvironments/scripts/builders/mamba.sh index 960e4a4c..bac948d5 100644 --- a/SwanCustomEnvironments/swancustomenvironments/scripts/builders/mamba.sh +++ b/SwanCustomEnvironments/swancustomenvironments/scripts/builders/mamba.sh @@ -1,23 +1,15 @@ #!/bin/bash -# Create the environment and install packages -mamba create -p ${ENV_PATH} --file ${REQ_PATH} -y | tee -a ${LOG_FILE} +# Create the environment, install packages and the same ipykernel that the Jupyter server uses +mamba create -p ${ENV_PATH} --file ${REQ_PATH} "ipykernel==${IPYKERNEL_VERSION}" -y | tee -a ${LOG_FILE} # Activate the environment _log "Setting up the environment..." -# Needed to use mamba activate without creating a new shell process +# Initialize mamba and send its activation script to the user's bash profile MAMBADIR=$(mktemp -d) HOME=${MAMBADIR} mamba init -ACTIVATE_MAMBA_CMD="source ${MAMBADIR}/.bashrc" -eval "${ACTIVATE_MAMBA_CMD}" +echo "source ${MAMBADIR}/.bashrc" >> /home/$USER/.bash_profile -# Then activate the environment using mamba +# Construct the activation command ACTIVATE_ENV_CMD="mamba activate ${ENV_PATH}" -eval "${ACTIVATE_ENV_CMD}" - -# Install the same ipykernel that the Jupyter server uses -mamba install "ipykernel==${IPYKERNEL_VERSION}" -y | tee -a ${LOG_FILE} - -# Source the mamba init script in the user's bash profile -echo "${ACTIVATE_MAMBA_CMD}" >> /home/$USER/.bash_profile \ No newline at end of file diff --git a/SwanCustomEnvironments/swancustomenvironments/scripts/builders/venv.sh b/SwanCustomEnvironments/swancustomenvironments/scripts/builders/venv.sh index 1fd51d0b..f565bab2 100644 --- a/SwanCustomEnvironments/swancustomenvironments/scripts/builders/venv.sh +++ b/SwanCustomEnvironments/swancustomenvironments/scripts/builders/venv.sh @@ -8,9 +8,6 @@ _log "Setting up the environment..." ACTIVATE_ENV_CMD="source ${ENV_PATH}/bin/activate" eval "${ACTIVATE_ENV_CMD}" -# Install packages in the environment +# Install packages in the environment and the same ipykernel that the Jupyter server uses _log "Installing packages from ${REQ_PATH}..." -pip install -r "${REQ_PATH}" | tee -a ${LOG_FILE} - -# Install the same ipykernel that the Jupyter server uses -pip install ipykernel==${IPYKERNEL_VERSION} | tee -a ${LOG_FILE} +pip install -r "${REQ_PATH}" "ipykernel==${IPYKERNEL_VERSION}" | tee -a ${LOG_FILE}