Skip to content
New issue

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

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

Already on GitHub? # to your account

ENH: Add additional environment to tox to run notebooks #35

Merged
merged 4 commits into from
Jan 20, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 4 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ jobs:
with:
path: /home/runner/nifreeze-tests/
key: data-v0
- name: Install TeX Live
run: |
sudo apt-get update
sudo apt install texlive texlive-latex-extra texlive-fonts-recommended cm-super dvipng
- name: Install tox
run: |
python -m pip install --upgrade pip
Expand Down
2 changes: 1 addition & 1 deletion docs/notebooks/bold_realignment.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"WORKDIR = Path.home() / \"tmp\" / \"nifreezedev\" / \"ismrm25\"\n",
"WORKDIR.mkdir(parents=True, exist_ok=True)\n",
"\n",
"OUTPUT_DIR = Path(\"/data/derivatives\") / \"nifreeze-ismrm25-exp2\"\n",
"OUTPUT_DIR = Path.home() / \"tmp\" / \"nifreezedev\" / \"ismrm25\" / \"nifreeze-ismrm25-exp2\"\n",
"OUTPUT_DIR.mkdir(exist_ok=True, parents=True)"
]
},
Expand Down
8 changes: 8 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,14 @@ test = [
"pytest-xdist >= 1.28"
]

notebooks = [
"jupyter",
"nbclient",
"nbmake",
"mriqc_learn",
"nipreps-synthstrip",
]

antsopt = [
"ConfigSpace",
"nipreps",
Expand Down
33 changes: 33 additions & 0 deletions tools/run_notebooks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
# vi: set ft=python sts=4 ts=4 sw=4 et:
#
# Copyright The NiPreps Developers <nipreps@gmail.com>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# We support and encourage derived works from this project, please read
# about our expectations at
#
# https://www.nipreps.org/community/licensing/
#

import glob
import subprocess
import sys

notebooks = glob.glob("docs/notebooks/*.ipynb")
# Make bold_realignment.ipynb Jupyter notebook an exception as it involves running a realignment
# process for several DataLad datasets, which requires long running times.
notebooks.remove("docs/notebooks/bold_realignment.ipynb")

sys.exit(subprocess.call(["pytest", "--nbmake"] + notebooks))
33 changes: 31 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
requires =
tox>=4
envlist =
py312
py312, notebooks
skip_missing_interpreters = true

# Configuration that allows us to split tests across GitHub runners effectively
[gh-actions]
python =
3.12: py312
3.12: py312, notebooks

[testenv]
description = Pytest with coverage
Expand Down Expand Up @@ -39,6 +39,35 @@ commands =
pytest --doctest-modules --cov nifreeze -n auto --cov-report xml \
--junitxml=test-results.xml -v src test {posargs}

[testenv:notebooks]
description = Run notebooks
labels = notebooks
pass_env =
# getpass.getuser() sources for Windows:
LOGNAME
USER
LNAME
USERNAME
# Pass user color preferences through
PY_COLORS
FORCE_COLOR
NO_COLOR
CLICOLOR
CLICOLOR_FORCE
CURBRANCH
GITHUB_ACTIONS
TEST_DATA_HOME
TEST_OUTPUT_DIR
TEST_WORK_DIR
PYTHONHASHSEED
ITK_GLOBAL_DEFAULT_NUMBER_OF_THREADS
PATH
extras = notebooks
commands =
# pytest --nbmake docs/notebooks/*.ipynb
# not working due to https://github.com/tox-dev/tox/issues/1571
python {toxinidir}/tools/run_notebooks.py

[testenv:docs]
description = Build documentation site
labels = docs
Expand Down
Loading