Skip to content

Run tests

Run tests #2891

Workflow file for this run

name: Run tests
env:
# variables copied from matplotlib's test workflow
NO_AT_BRIDGE: 1 # Necessary for GTK3 interactive test.
OPENBLAS_NUM_THREADS: 1
PYTHONFAULTHANDLER: 1
# Controls when the action will run.
on:
# run on push, manual dispatch and on a schedule
# when run on schedule, tests will only be run if a new matplotlib release was found
workflow_dispatch:
inputs:
ignore-mpl-version:
type: boolean
required: true
description: Run independent of current and last tested Matplotlib version
push:
branches-ignore:
- gh-pages
schedule:
- cron: '0 */8 * * *'
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# Check for new matplotlib releases and run tests if a new release is available
run-test:
# The type of runner that the job will run on
runs-on: ubuntu-22.04
steps:
- name: Get current stable Matplotlib version
id: mpl-sources
run: |
# Find out what's the latest version number of matplotlib and
# create a url for downloading the sources for that version.
# Read last runs version from a cached file if available. Set to 'unknown' otherwise.
# Set these as this steps outputs so they can be reused later.
sudo apt-get update -yy && sudo apt-get install -yy curl
CURRENT_MPL_VERSION=$(curl -s https://api.github.com/repos/matplotlib/matplotlib/releases/latest \
| grep "tag_name" \
| awk '{print substr($2, 3, length($2)-4)}')
MPL_LOCATION=$"https://github.com/matplotlib/matplotlib/archive/v$CURRENT_MPL_VERSION.tar.gz"
echo "current=$CURRENT_MPL_VERSION" >> "$GITHUB_OUTPUT"
echo "location=$MPL_LOCATION" >> "$GITHUB_OUTPUT"
# cached version file is used to remember the matplotlib release version
# number from the last run
- name: Cache version from last run
uses: actions/cache@v3
with:
path: mpl_version_last_run.txt
# ensure that the primary key is different on every run by including ids that are unique for each run
# this ensures that the cache is always updated because there is no hit on the primary key
# we do only know if the cache needs to be updated after restoring the cache and looking at its content, therefore, just always update
key: version-cache-${{ github.run_id }}-${{ github.run_attempt }}
restore-keys: |
version-cache
# check which is the newest matplotlib release version number
# determine whether to actually run tests depending on current and last release number
# and on the event that triggered the run
- name: Version Check
id: version
run: |
if test -f "mpl_version_last_run.txt"
then
LAST_MPL_VERSION=$(<mpl_version_last_run.txt)
else
LAST_MPL_VERSION="unknown"
fi
if [ -z ${{ inputs.ignore-mpl-version }} ]
then
IGNORE_MPL_VERSION='unset'
else
IGNORE_MPL_VERSION=${{ inputs.ignore-mpl-version }}
fi
echo "Event that triggered this run: ${{ github.event_name }}"
echo "Manual override to force running independent of versions is $IGNORE_MPL_VERSION"
echo "The current matplotlib version is ${{ steps.mpl-sources.outputs.current }}"
echo "URL for sources: ${{ steps.mpl-sources.outputs.location }}"
echo "The matplotlib version on the last run was $LAST_MPL_VERSION"
echo ""
if [[ "${{ github.event_name }}" == "schedule" ]] && [[ "$LAST_MPL_VERSION" != "${{ steps.mpl-sources.outputs.current }}" ]]
then
echo "Scheduled run, versions differ, tests will be run! Continuing..."
RUN_TESTS="yes"
elif [[ "${{ github.event_name }}" == "push" ]]
then
echo "Triggered by push, assume sources changed, tests will be run! Continuing..."
RUN_TESTS="yes"
elif [[ "${{ github.event_name }}" == "workflow_dispatch" ]] && [[ "$LAST_MPL_VERSION" != "${{ steps.mpl-sources.outputs.current }}" ]]
then
echo "Manual run, versions differ, tests will be run! Continuing..."
RUN_TESTS="yes"
elif [[ "${{ github.event_name }}" == "workflow_dispatch" ]] && [[ $IGNORE_MPL_VERSION == 'true' ]]
then
echo "Manual run, version comparison overridden, tests will be run! Continuing..."
RUN_TESTS="yes"
else
echo "Tests will not be run! Exiting..."
RUN_TESTS="no"
fi
echo "last=$LAST_MPL_VERSION" >> "$GITHUB_OUTPUT"
echo "run=$RUN_TESTS" >> "$GITHUB_OUTPUT"
- name: Setup python
if: steps.version.outputs.run == 'yes'
uses: actions/setup-python@v4
with:
python-version: 3.9 # Version range or exact version of a Python version to use, using SemVer's version range syntax
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- name: Checkout repo
if: steps.version.outputs.run == 'yes'
uses: actions/checkout@v4
- name: Install OS dependencies
if: steps.version.outputs.run == 'yes'
run: |
sudo apt-get update -yy
sudo apt-get install -yy \
ccache \
cm-super \
dvipng \
ffmpeg \
fonts-noto-cjk \
gdb \
gir1.2-gtk-3.0 \
graphviz \
inkscape \
lcov \
libcairo2 \
libcairo2-dev \
libffi-dev \
libgeos-dev \
libgirepository1.0-dev \
libsdl2-2.0-0 \
libxkbcommon-x11-0 \
libxcb-cursor0 \
libxcb-icccm4 \
libxcb-image0 \
libxcb-keysyms1 \
libxcb-randr0 \
libxcb-render-util0 \
libxcb-xinerama0 \
lmodern \
fonts-freefont-otf \
texlive-pictures \
pkg-config \
qtbase5-dev \
texlive-fonts-recommended \
texlive-latex-base \
texlive-latex-extra \
texlive-latex-recommended \
texlive-luatex \
texlive-xetex \
ttf-wqy-zenhei \
libopengl0
- name: Cache pip
if: steps.version.outputs.run == 'yes'
uses: actions/cache@v3
with:
path: ~/.cache/pip
key: pip-cache-${{ hashFiles('requirements.txt') }}
restore-keys: |
pip-cache
- name: Clone latest released sources for matplotlib
if: steps.version.outputs.run == 'yes'
run: |
git clone --depth 1 --branch v${{ steps.mpl-sources.outputs.current }} https://github.com/matplotlib/matplotlib.git
- name: Install Python dependencies
if: steps.version.outputs.run == 'yes'
run: |
# Upgrade pip and setuptools and wheel to get as clean an install as
# possible.
python3 -m pip install --upgrade pip setuptools wheel
# Install dependencies from PyPI.
python3 -m pip install --upgrade \
'contourpy>=1.0.1' cycler fonttools kiwisolver importlib_resources \
numpy packaging pillow pyparsing python-dateutil setuptools-scm \
-r matplotlib/requirements/testing/all.txt \
-r matplotlib/requirements/testing/extra.txt
# Install optional dependencies from PyPI.
# Sphinx is needed to run sphinxext tests
python3 -m pip install --upgrade sphinx!=6.1.2
# GUI toolkits are pip-installable only for some versions of Python
# so don't fail if we can't install them. Make it easier to check
# whether the install was successful by trying to import the toolkit
# (sometimes, the install appears to be successful but shared
# libraries cannot be loaded at runtime, so an actual import is a
# better check).
# PyGObject, pycairo, and cariocffi do not install on OSX 10.12.
python -m pip install --upgrade pycairo 'cairocffi>=0.8' PyGObject &&
python -c 'import gi; gi.require_version("Gtk", "3.0"); from gi.repository import Gtk' &&
echo 'PyGObject is available' ||
echo 'PyGObject is not available'
# There are no functioning wheels available for OSX 10.12 (as of
# Sept 2020) for either pyqt5 (there are only wheels for 10.13+) or
# pyside2 (the latest version (5.13.2) with 10.12 wheels has a
# fatal to us bug, it was fixed in 5.14.0 which has 10.13 wheels)
python -mpip install --upgrade pyqt5 &&
python -c 'import PyQt5.QtCore' &&
echo 'PyQt5 is available' ||
echo 'PyQt5 is not available'
python -mpip install --upgrade pyqt6 &&
python -c 'import PyQt6.QtCore' &&
echo 'PyQt6 is available' ||
echo 'PyQt6 is not available'
python -mpip install --upgrade pyside6 &&
python -c 'import PySide6.QtCore' &&
echo 'PySide6 is available' ||
echo 'PySide6 is not available'
python -mpip install --upgrade \
-f "https://extras.wxpython.org/wxPython4/extras/linux/gtk3/ubuntu-20.04" \
wxPython &&
python -c 'import wx' &&
echo 'wxPython is available' ||
echo 'wxPython is not available'
- name: Install matplotlib from sources
if: steps.version.outputs.run == 'yes'
run: |
cd matplotlib
cat <<EOT >> mplsetup.cfg
[rc_options]
backend=Agg
EOT
cat mplsetup.cfg
python -m pip install --no-deps -ve .
- name: Run Timple Tests
if: steps.version.outputs.run == 'yes'
run: |
python3 -m pip install -r requirements-dev.txt # ensure package requirements
xvfb-run -a python3 -m pytest -raR
- name: Update mpl version cache file
if: steps.version.outputs.run == 'yes'
run: |
echo "${{ steps.mpl-sources.outputs.current }}" > mpl_version_last_run.txt