#!/usr/bin/env bash


set -e

[ -n "${SAGE_ROOT}" ] || SAGE_ROOT="$(readlink -f $(dirname ${0})/../../../)"


# Set the version and its download URL.
VERSION=2.2.2
DOWNLOAD_URL="https://github.com/matplotlib/matplotlib/archive/v${VERSION}.tar.gz"

# fetch and unpack latest version
tar xzf <( curl -L ${DOWNLOAD_URL} )


# 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}" > "${SAGE_ROOT}/build/pkgs/matplotlib/package-version.txt"
"$SAGE_ROOT"/sage --package fix-checksum matplotlib

