Skip to content

Commit

Permalink
Split conda activate into three cases
Browse files Browse the repository at this point in the history
1) No env active, just activate the flepiMoP env.
2) The flepiMoP env is active, go ahead and refresh it because
   `module load anaconda` modifies the paths.
3) Another conda env is active, deactivate it with a message.
  • Loading branch information
TimothyWillard committed Nov 8, 2024
1 parent d7345dd commit 8da1720
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions batch/hpc_init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,14 @@ if [ -z "${FLEPI_CONDA}" ]; then
echo "Using '$FLEPI_CONDA' for \$FLEPI_CONDA."
fi
CURRENT_CONDA_ENV=$( conda info | grep "active environment" | awk -F ':' '{print $2}' | xargs )
if [ "$CURRENT_CONDA_ENV" != "None" ] && [ "$CURRENT_CONDA_ENV" != "$FLEPI_CONDA" ]; then
echo "Detected an active conda environment '$CURRENT_CONDA_ENV'. This will be deactivated and the '$FLEPI_CONDA' environment will be activated."
if [ "$CURRENT_CONDA_ENV" = "$FLEPI_CONDA" ]; then
echo "Detected the activate conda environment is '$FLEPI_CONDA' already, but will refresh."
conda deactivate
elif [ "$CURRENT_CONDA_ENV" != "None" ]; then
echo "Detected an active conda environment '$CURRENT_CONDA_ENV'. This will be deactivated and the '$FLEPI_CONDA' environment wil be activated."
conda deactivate
fi
if [ "$CURRENT_CONDA_ENV" == "None" ] || [ "$CURRENT_CONDA_ENV" != "$FLEPI_CONDA" ]; then
conda activate $FLEPI_CONDA
fi
conda activate $FLEPI_CONDA

# Check the conda environment is valid
WHICH_PYTHON=$( which python )
Expand Down

0 comments on commit 8da1720

Please sign in to comment.