Skip to content

Instantly share code, notes, and snippets.

@mingwandroid
Created June 14, 2016 01:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mingwandroid/a5a2805b8f4ef164bff2dd31868d1de8 to your computer and use it in GitHub Desktop.
Save mingwandroid/a5a2805b8f4ef164bff2dd31868d1de8 to your computer and use it in GitHub Desktop.
Shell script that I use to bootstrap my conda environments (it's always in-flux)
#!/usr/bin/env bash
if [[ -n $BASH_VERSION ]] && [[ "$(basename "$0" 2> /dev/null)" == "mc-opts" ]]; then
>&2 echo "Error: mc must be sourced. Run 'source $0 $*'"
exit 1
fi
script_dir=$( cd $( dirname "${BASH_SOURCE[0]}" ) && pwd )
while [ "$#" -gt 0 ]; do
OPT="$1"
case "$1" in
-*=*)
VAR=$(echo $1 | sed "s,^-\(.*\)=.*,\1,")
VAL=$(echo $1 | sed "s,^-.*=\(.*\),\1,")
;;
-*)
VAR=$(echo $1 | sed "s,^-\(.*\),\1,")
VAL=1
;;
esac
VAR=$(echo "$VAR" | tr '[a-z]' '[A-Z]')
eval "$VAR=\$VAL"
shift
OPTIONS_DEBUG=$OPTIONS_DEBUG" $VAR=$VAL"
done
if [[ "${PYVER}" == "2" ]]; then
PYVER=2.7
elif [[ "${PYVER}" == "3" ]]; then
PYVER=3.5
fi
if [[ -z ${PREFIX} ]]; then
PREFIX=mc
fi
# To get the value of a single parameter, just remember to include the `-`
echo The value of -prefix is: $PREFIX
echo The value of -pyver is: $PYVER
echo The value of -maximal is: $MAXIMAL
echo The value of -buildconda is: $BUILDCONDA
if [[ "${PYVER}" != "2.7" && "${PYVER}" != "3.4" && "${PYVER}" != "3.5" ]]; then
echo "ERROR: Valid arguments are 2, 2.7, 3 - selects 3.5, 3.4, and 3.5"
return 1
fi
if [[ "$(uname -m)" == "x86_64" ]]; then
FOLDARCHSUF=-x64
DLSUF=x86_64
else
FOLDARCHSUF=-x86
DLSUF=x86
fi
CONDAMAJVER=${PYVER%.*}
CONDAPATH=${HOME}/${PREFIX}${FOLDARCHSUF}-${PYVER}
if [[ "$(uname)" == "Darwin" ]]; then
CONDAOS=MacOSX
elif [[ $(uname) =~ (MSYS|MINGW).* ]]; then
CONDAOS=Windows
else
CONDAOS=Linux
fi
if [[ "${CONDAOS}" == "Windows" ]]; then
export CONDA_R=3.3.0
else
export CONDA_R=3.2.2
fi
if [[ ! -d ${CONDAPATH} ]]; then
URL=https://repo.continuum.io/miniconda/Miniconda${CONDAMAJVER}-latest-${CONDAOS}-${DLSUF}.sh
FNAME=$(basename ${URL})
if [[ ! -d ${HOME}/Downloads ]]; then
mkdir -p ${HOME}/Downloads
fi
curl --url ${URL} --output ${HOME}/Downloads/${FNAME}
bash ${HOME}/Downloads/${FNAME} -b -p ${CONDAPATH}
source ${CONDAPATH}/bin/activate ${CONDAPATH}
conda update conda -y
# Don't use unxutils here, see https://github.com/conda/conda-build/issues/495
conda install python=${PYVER} anaconda-client conda-build pytest pytest-cov nose pyflakes flake8 -y
if [[ "${CONDAOS}" == "Windows" ]]; then
conda install m2-patch -c msys2 -y
fi
if [[ -n "${MAXIMAL}" ]]; then
conda install -c spyder-ide spyder -y
fi
fi
if [[ "${CONDAOS}" == "Windows" ]]; then
source ${CONDAPATH}/Scripts/activate ${CONDAPATH}
else
source ${CONDAPATH}/bin/activate ${CONDAPATH}
fi
if [[ -n "${BUILDCONDA}" ]]; then
pushd $HOME/conda/conda-build
git clean -dxf -e .idea .
python setup.py install
popd
pushd $HOME/conda/conda
git clean -dxf -e .idea .
CONDA_DEFAULT_ENV= python setup.py install
popd
fi
# sudo apt-get install gfortran
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment