#!/usr/bin/env modbuild

pbuild::prep() {
    :
}

pbuild::configure() {
    :
}

pbuild::compile() {
    :
}

pbuild::install() {
    # ccp4/9.0 is a build_requires, so ccp4-python is on PATH here.
    command -v ccp4-python >/dev/null || \
        std::die 42 "PanDDA: ccp4-python not on PATH — ccp4/9.0 module did not load"

    # Vendor doc says: uninstall bundled panddas, upgrade pip+numpy, pip install
    # panddas — all of which would mutate the shared ccp4/9.0 module. Instead:
    # --prefix keeps everything inside this module, --ignore-installed pulls
    # fresh deps (incl. numpy) here rather than reusing/soiling ccp4's, and the
    # modulefile's PYTHONPATH prepend shadows the ccp4-bundled panddas.
    ccp4-python -m pip install --prefix="${PREFIX}" --ignore-installed \
        "panddas==${V_PKG}" || \
        std::die 42 "PanDDA: pip install failed — check network and ccp4-python version"

    # stable alias so the modulefile needn't know ccp4's python X.Y
    local -a sp=( "${PREFIX}"/lib/python*/site-packages )
    [[ -d "${sp[0]}" ]] || std::die 42 "PanDDA: no site-packages under ${PREFIX}/lib"
    ln -sfn "${sp[0]#"${PREFIX}"/}" "${PREFIX}/site-packages"

    [[ -x "${PREFIX}/bin/pandda.analyse" ]] || \
        std::die 42 "PanDDA: bin/pandda.analyse missing — install incomplete"
}
