#!/usr/bin/env bash
# From sage-spkg.
# For type=script packages, the build rule in build/make/Makefile sources
# sage-env but not sage-dist-helpers.
lib="$SAGE_ROOT/build/bin/sage-dist-helpers"
source "$lib"
if [ $? -ne 0 ]; then
    echo >&2 "Error: failed to source $lib"
    echo >&2 "Is $SAGE_ROOT the correct SAGE_ROOT?"
    exit 1
fi
cd src

export PIP_NO_INDEX=true
export PIP_FIND_LINKS="file://$SAGE_SPKG_WHEELS"

if [ "$SAGE_EDITABLE" = yes ]; then
    # SAGE_ROOT/src/setup.py installs everything, nothing to do...
    if [ "$SAGE_WHEELS" = yes ]; then
        # ... except we build the wheel if requested
        sdh_setup_bdist_wheel && sdh_store_wheel .
    fi
else
    if [ "$SAGE_WHEELS" = yes ]; then
        # Modularized install via wheels
        sdh_pip_install .
    # else nothing to do in legacy direct installation.
    fi
fi
