#!/usr/bin/env bash

# Run the system python.
#
# This is primarily for use by the build toolchain so that it can continue
# using the system Python rather than Sage's Python, preventing conflicts
# that might otherwise occur, particularly in parallel builds.
#
# See https://trac.sagemath.org/ticket/18438

if [ -z "$SAGE_ORIG_PATH" ]; then
    # If not we're running from within sage-env just set the existing path
    SAGE_ORIG_PATH="$PATH"
fi

PYTHON="$(PATH="$SAGE_ORIG_PATH" command -v python)"

# fallback for systems where only the python3 command is available
# see https://trac.sagemath.org/ticket/26953
if [ -z "$PYTHON" ]; then
    PYTHON="$(PATH="$SAGE_ORIG_PATH" command -v python3)"
fi

exec "$PYTHON" "$@"
