Skip to content

Commit

Permalink
Add tolerance to network errors by permitting conda to retry
Browse files Browse the repository at this point in the history
As title.
  • Loading branch information
stuartarchibald committed Mar 20, 2019
1 parent 8739d1e commit 33a90fe
Showing 1 changed file with 29 additions and 3 deletions.
32 changes: 29 additions & 3 deletions buildscripts/incremental/setup_conda_environment.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,32 @@

set -v -e

CONDA_INSTALL="conda install -q -y"
network_tolerant_conda() {
local cmd=$1
shift
local attempts=$1
shift
for i in `seq $(($attempts + 1))`; do
conda $cmd -q -y $*
if [ $? == 0 ]; then
break;
else
if [ $i != $(($attempts + 1)) ]; then
echo "Connection/conda problem... retrying (attempt $i/$attempts)"
else
msg="Unresolved connection/conda problem...
exiting after $attempts additional attempts"
echo $msg
exit 1
fi
fi
done
}

CONDA_INSTALL="network_tolerant_conda install 3"
CONDA_CREATE="network_tolerant_conda create 3"
CONDA_REMOVE="network_tolerant_conda remove 3"
CONDA_EXPORT="network_tolerant_conda export 3"
PIP_INSTALL="pip install -q"


Expand All @@ -14,19 +39,20 @@ fi

# Deactivate any environment
source deactivate

# Display root environment (for debugging)
conda list
# Clean up any left-over from a previous build
# (note workaround for https://github.com/conda/conda/issues/2679:
# `conda env remove` issue)
conda remove --all -q -y -n $CONDA_ENV
$CONDA_REMOVE --all -n $CONDA_ENV

# If VANILLA_INSTALL is yes, then only Python, NumPy and pip are installed, this
# is to catch tests/code paths that require an optional package and are not
# guarding against the possibility that it does not exist in the environment.
# Create a base env first and then add to it...

conda create -n $CONDA_ENV -q -y ${EXTRA_CHANNELS} python=$PYTHON numpy=$NUMPY pip
$CONDA_CREATE -n $CONDA_ENV ${EXTRA_CHANNELS} python=$PYTHON numpy=$NUMPY pip

# Activate first
set +v
Expand Down

0 comments on commit 33a90fe

Please sign in to comment.