Skip to content

Commit

Permalink
swancustomenvs: Install ipykernel with requirements
Browse files Browse the repository at this point in the history
Install requirements at the same time as the remaining requirements for better performance
  • Loading branch information
rodrigo-sobral authored and etejedor committed Sep 20, 2024
1 parent 7392c11 commit 6dfbb8f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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}

0 comments on commit 6dfbb8f

Please sign in to comment.