Skip to content

Commit b9fb06e

Browse files
authored
Merge pull request #26 from bsipocz/CI_adding_test_matrix_and_configs
CI: adding tox and a test matrix
2 parents 36560f8 + f39887c commit b9fb06e

File tree

4 files changed

+139
-0
lines changed

4 files changed

+139
-0
lines changed
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
name: Test notebooks
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
branches:
9+
- main
10+
schedule:
11+
- cron: '0 5 * * 1'
12+
workflow_dispatch:
13+
14+
concurrency:
15+
group: ${{ github.workflow }}-${{ github.ref }}
16+
cancel-in-progress: true
17+
18+
jobs:
19+
tests:
20+
# Do not run the test matrix on PRs affecting the rendering
21+
if: ${{ !(github.event_name == 'pull_request') || !contains(github.event.pull_request.labels.*.name, 'html rendering / skip testing') }}
22+
23+
name: ${{ matrix.os }} ${{ matrix.name }}
24+
runs-on: ${{ matrix.os }}
25+
strategy:
26+
fail-fast: false
27+
matrix:
28+
# Run all supported OS for one Python version, then add a few extra scenarios
29+
os: [ubuntu-latest, macos-latest, windows-latest]
30+
python-version: ['3.12']
31+
toxenv: [py312-test]
32+
name: ['with Python 3.12',]
33+
34+
include:
35+
- python-version: '3.10'
36+
toxenv: py310-test-oldestdeps
37+
name: with Python 3.10 and oldest versioned dependencies
38+
os: ubuntu-latest
39+
40+
- python-version: '3.13'
41+
toxenv: py313-test-devdeps
42+
name: with Python 3.13 and developer versioned dependencies
43+
os: ubuntu-latest
44+
45+
steps:
46+
- uses: actions/checkout@v4
47+
- name: Set up Python ${{ matrix.python-version }}
48+
uses: actions/setup-python@v5
49+
with:
50+
python-version: ${{ matrix.python-version }}
51+
52+
- name: Install dependencies
53+
run: python -m pip install --upgrade tox
54+
55+
- name: Test with tox
56+
run: tox ${{ matrix.toxargs }} -e ${{ matrix.toxenv }} -- ${{ matrix.toxposargs }}
57+
58+
59+
gha_buildhtml:
60+
# When label is used, we do run buildhtml on GHA to check if the publishing job will run or not.
61+
# Use in case when new content has run into troubles on CircleCI.
62+
if: ${{ (github.event_name == 'pull_request') && contains(github.event.pull_request.labels.*.name, 'GHA buildhtml') }}
63+
name: Buildhtml testing
64+
runs-on: ubuntu-latest
65+
steps:
66+
- uses: actions/checkout@v4
67+
68+
- name: Setup Python
69+
uses: actions/setup-python@v5
70+
with:
71+
python-version: '3.11'
72+
73+
- name: Install dependencies
74+
run: python -m pip install --upgrade tox
75+
76+
- name: Execute notebooks as testing
77+
run: tox -e py311-buildhtml

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
_build/*
22
.ipynb_checkpoints
33
/.pixi/*
4+
# Notebooks are stored in the text-based Markdown format.
5+
# No .ipynb files should be stored in this repository.
6+
*.ipynb
7+
48
# We treat this repository as a library, not an application, and thus we do not
59
# include the lockfile in source control. For a specific event, like a
610
# workshop, we suggest committing the lockfile on a branch dedicated to the

requirements.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,8 @@ ipympl
66
sphinx-copybutton
77
# For tutorials
88
matplotlib
9+
# for testing
10+
pytest
11+
nbval
12+
pytest-custom_exit_code
13+
jupytext

tox.ini

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
[tox]
2+
envlist =
3+
py{311, 312, 313}-test{,-oldestdeps,-devdeps,-predeps}{,-buildhtml}
4+
requires =
5+
pip >= 19.3.1
6+
7+
[testenv]
8+
9+
description = run tests
10+
11+
setenv =
12+
devdeps: PIP_EXTRA_INDEX_URL = https://pypi.anaconda.org/scientific-python-nightly-wheels/simple
13+
14+
passenv = CI, CIRCLECI, GITHUB_EVENT_NAME, GITHUB_EVENT_PATH
15+
16+
deps =
17+
# We use these files to specify all the dependencies, and below we override
18+
# versions for specific testing schenarios
19+
-rrequirements.txt
20+
#-rsite_requirements.txt
21+
#-r.binder/requirements.txt
22+
23+
# Notebooks may set minimums for some dependencies, the others are set for a supported minimum
24+
# following e.g. SPEC0 or some other considerations.
25+
oldestdeps: numpy==1.24.0
26+
oldestdeps: matplotlib==3.7.0
27+
28+
# TODO: add pure python dependency, so we can add an example for the github install
29+
devdeps: git+https://github.com/astropy/pyvo.git#egg=pyvo
30+
31+
allowlist_externals = bash, sed
32+
33+
commands =
34+
pip freeze
35+
36+
## Some of the these could be factored out to a separate shell script,
37+
## but so far it's simple enought to keep it here.
38+
39+
# We only want to run CI in PRs for the notebooks we touched
40+
!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 '
41+
42+
!buildhtml: pytest --nbval-lax -vv --suppress-no-test-exit-code --durations=10 tutorials
43+
44+
buildhtml: sphinx-build -b html . _build/html -nWT --keep-going
45+
# SED magic to remove the toctree captions from the rendered index page while keeping them in the sidebar TOC
46+
buildhtml: sed -E -i.bak '/caption-text/{N; s/.+caption-text.+\n<ul>/<ul>/; P;D;}' _build/html/index.html
47+
buildhtml: bash -c 'rm _build/html/index.html.bak'
48+
49+
pip_pre =
50+
predeps: true
51+
!predeps: false
52+
53+
skip_install = true

0 commit comments

Comments
 (0)