#!/usr/bin/env bash


# Run the Python interpreter that we are currently building Sage with
#
# An existing Python is a build-time dependency for Sage, but
# sometimes packages need to specifically run the one in Sage and not
# just any Python interpreter.
#
# This is similar to the sage-pip-install script, which you should be
# using for installing Python packages if at all possible.


if [ "$SAGE_PYTHON3" = yes ]; then
   PYTHON="$SAGE_LOCAL/bin/python3"
else
   PYTHON="$SAGE_LOCAL/bin/python2"
fi

# Check that Python is actually installed and issue an error message if not--in
# particular if this was run from an spkg-install before Python is installed
# this indicates that Python should be a dependency of that package.
if [ ! -x "$PYTHON" ]; then
     echo >&2 "Error: Tried to use Sage's Python which was not yet installed."
     echo >&2 'If this was called from an spkg-install script for another '
     echo >&2 'package you should add $(PYTHON) as a dependency in '
     echo >&2 'build/pkgs/<pkg>/dependencies'
     exit 1
fi

exec $PYTHON "$@"
