if [ "$SAGE_LOCAL" = "" ]; then
   echo "SAGE_LOCAL undefined ... exiting";
   echo "Maybe run 'sage -sh'?"
   exit 1
fi

# distribute doesn't allow itself to be replaced by setuptools
# so we manually have to delete it
# (pip actually can uninstall setuptools but we may not have pip
# install yet)
rm -rf "$SAGE_LOCAL"/lib/python*/site-packages/setuptools*
rm -rf "$SAGE_LOCAL"/lib/python*/site-packages/distribute*

export PYTHON_EGG_CACHE="$DOT_SAGE/.python-eggs"

cd src

# Prevent setuptools from installing itself with easy_install
python2 setup.py --no-user-cfg install --single-version-externally-managed --record=/dev/null
if [ $? -ne 0 ]; then
    echo "Error Python 2 building / installing setuptools"
    exit 1
fi

python3 setup.py --no-user-cfg install --single-version-externally-managed --record=/dev/null
if [ $? -ne 0 ]; then
    echo "Error Python 3 building / installing setuptools"
    exit 1
fi
