Skip to content

CI: adding tox and a test matrix #26

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 77 additions & 0 deletions .github/workflows/ci_tests_run_notebooks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
name: Test notebooks

on:
push:
branches:
- main
pull_request:
branches:
- main
schedule:
- cron: '0 5 * * 1'
workflow_dispatch:

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
tests:
# Do not run the test matrix on PRs affecting the rendering
if: ${{ !(github.event_name == 'pull_request') || !contains(github.event.pull_request.labels.*.name, 'html rendering / skip testing') }}

name: ${{ matrix.os }} ${{ matrix.name }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
# Run all supported OS for one Python version, then add a few extra scenarios
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: ['3.12']
toxenv: [py312-test]
name: ['with Python 3.12',]

include:
- python-version: '3.10'
toxenv: py310-test-oldestdeps
name: with Python 3.10 and oldest versioned dependencies
os: ubuntu-latest

- python-version: '3.13'
toxenv: py313-test-devdeps
name: with Python 3.13 and developer versioned dependencies
os: ubuntu-latest

steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@82c7e631bb3cdc910f68e0081d67478d79c6982d #v5.1.0
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: python -m pip install --upgrade tox

- name: Test with tox
run: tox ${{ matrix.toxargs }} -e ${{ matrix.toxenv }} -- ${{ matrix.toxposargs }}


gha_buildhtml:
# When label is used, we do run buildhtml on GHA to check if the publishing job will run or not.
# Use in case when new content has run into troubles on CircleCI.
if: ${{ (github.event_name == 'pull_request') && contains(github.event.pull_request.labels.*.name, 'GHA buildhtml') }}
name: Buildhtml testing
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: '3.11'

- name: Install dependencies
run: python -m pip install --upgrade tox

- name: Execute notebooks as testing
run: tox -e py311-buildhtml
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
_build/*
.ipynb_checkpoints
/.pixi/*
*.ipynb

# We treat this repository as a library, not an application, and thus we do not
# include the lockfile in source control. For a specific event, like a
# workshop, we suggest committing the lockfile on a branch dedicated to the
Expand Down
5 changes: 5 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,8 @@ ipympl
sphinx-copybutton
# For tutorials
matplotlib
# for testing
pytest
nbval
pytest-custom_exit_code
jupytext
53 changes: 53 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
[tox]
envlist =
py{311, 312, 313}-test{,-oldestdeps,-devdeps,-predeps}{,-buildhtml}
requires =
pip >= 19.3.1

[testenv]

description = run tests

setenv =
devdeps: PIP_EXTRA_INDEX_URL = https://pypi.anaconda.org/scientific-python-nightly-wheels/simple

passenv = CI, CIRCLECI, GITHUB_EVENT_NAME, GITHUB_EVENT_PATH

deps =
# We use these files to specify all the dependencies, and below we override
# versions for specific testing schenarios
-rrequirements.txt
#-rsite_requirements.txt
#-r.binder/requirements.txt

# Notebooks may set minimums for some dependencies, the others are set for a supported minimum
# following e.g. SPEC0 or some other considerations.
oldestdeps: numpy==1.24.0
oldestdeps: matplotlib==3.7.0

# TODO: add pure python dependency, so we can add an example for the github install
devdeps: git+https://github.com/astropy/pyvo.git#egg=pyvo

allowlist_externals = bash, sed

commands =
pip freeze

## Some of the these could be factored out to a separate shell script,
## but so far it's simple enought to keep it here.

# We only want to run CI in PRs for the notebooks we touched
!buildhtml: bash -c 'if [[ $GITHUB_EVENT_NAME == pull_request && -z "$(grep force_run:all_tests ${GITHUB_EVENT_PATH})" ]]; then git fetch origin main --depth=1; git diff origin/main --name-only tutorials | grep .md; else find tutorials -name "*.md"; fi | grep -vf ignore_testing | xargs jupytext --to notebook '

!buildhtml: pytest --nbval-lax -vv --suppress-no-test-exit-code --durations=10 tutorials

buildhtml: sphinx-build -b html . _build/html -nWT --keep-going
# SED magic to remove the toctree captions from the rendered index page while keeping them in the sidebar TOC
buildhtml: sed -E -i.bak '/caption-text/{N; s/.+caption-text.+\n<ul>/<ul>/; P;D;}' _build/html/index.html
buildhtml: bash -c 'rm _build/html/index.html.bak'

pip_pre =
predeps: true
!predeps: false

skip_install = true