#!/usr/bin/env bash


set -e

if [ -z "${SAGE_ROOT}" ]; then
    echo >&2 "This must be run within a Sage shell"
    exit 1
fi


VERSION=2.2.4
pip download --no-deps --no-binary :all: "matplotlib==${VERSION}"
tar xzf "matplotlib-${VERSION}.tar.gz"


# remove test images
rm -rf matplotlib-${VERSION}/lib/matplotlib/tests/baseline_images/*


# repack and cleanup temporary directory
tar cjf "$SAGE_ROOT/upstream/matplotlib-${VERSION}.tar.bz2" matplotlib-${VERSION}
rm -rf matplotlib-${VERSION}*


# update package info
echo "${VERSION}.p0" >"${SAGE_ROOT}/build/pkgs/matplotlib/package-version.txt"
sage --package fix-checksum matplotlib
