From cb2e4ba8cb3bdf0783e838070e8398e47fce9c9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jon=20Haitz=20Legarreta=20Gorro=C3=B1o?= Date: Fri, 8 Nov 2024 18:16:15 -0500 Subject: [PATCH 1/3] ENH: Add additional environment to `tox` to run notebooks Add an additional environment to `tox` to run notebooks. Add a new table to `pyproject.toml` to host the `jupyter`, `nbclient` and `nbmake` dependencies so that the notebooks can be run. Install the necessary TeX packages in the test CI so that LaTeX decoration in plots can be employed. Install the necessary additional Python packages used across the notebooks. Add a helper Python script to actually run the notebooks since `tox` does not expand wildcards currently. --- .github/workflows/test.yml | 4 ++++ pyproject.toml | 8 ++++++++ tools/run_notebooks.py | 28 ++++++++++++++++++++++++++++ tox.ini | 33 +++++++++++++++++++++++++++++++-- 4 files changed, 71 insertions(+), 2 deletions(-) create mode 100644 tools/run_notebooks.py diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index fbc70607..a1acb0d7 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -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 diff --git a/pyproject.toml b/pyproject.toml index aff2930e..912b6f09 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -74,6 +74,14 @@ test = [ "pytest-xdist >= 1.28" ] +notebooks = [ + "jupyter", + "nbclient", + "nbmake", + "mriqc_learn", + "nipreps-synthstrip", +] + antsopt = [ "ConfigSpace", "nipreps", diff --git a/tools/run_notebooks.py b/tools/run_notebooks.py new file mode 100644 index 00000000..8a75a66d --- /dev/null +++ b/tools/run_notebooks.py @@ -0,0 +1,28 @@ +# 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 +# +# 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 + +sys.exit(subprocess.call(["pytest", "--nbmake"] + glob.glob("docs/notebooks/*.ipynb"))) diff --git a/tox.ini b/tox.ini index 89395909..e3672d1f 100644 --- a/tox.ini +++ b/tox.ini @@ -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 @@ -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 From c268d0424b0e6a5ac5700e610aa89d2579be9542 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jon=20Haitz=20Legarreta=20Gorro=C3=B1o?= Date: Sat, 18 Jan 2025 17:23:47 -0500 Subject: [PATCH 2/3] ENH: Store bold realignment results in reachable path Store bold realignment results in a folder that actually exists. Fixes: ``` FAILED docs/notebooks/bold_realignment.ipynb::bold_realignment.ipynb - PermissionError: [Errno 13] Permission denied: '/data/derivatives' ``` raised for example in: https://github.com/nipreps/nifreeze/actions/runs/12847776534/job/35824459079?pr=35#step:12:1684 --- docs/notebooks/bold_realignment.ipynb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/notebooks/bold_realignment.ipynb b/docs/notebooks/bold_realignment.ipynb index b9d96476..55bf7916 100644 --- a/docs/notebooks/bold_realignment.ipynb +++ b/docs/notebooks/bold_realignment.ipynb @@ -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)" ] }, From 56f6b2ce841316116e9d4444c59c86ce1c5f0e89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jon=20Haitz=20Legarreta=20Gorro=C3=B1o?= Date: Mon, 20 Jan 2025 12:29:45 -0500 Subject: [PATCH 3/3] ENH: Skip BOLD realignment notebook in GHA CI testing Skip BOLD realignment notebook in GHA CI testing, as it involves running a realignment process for several DataLad datasets, which requires long running times. --- tools/run_notebooks.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tools/run_notebooks.py b/tools/run_notebooks.py index 8a75a66d..f9506f4c 100644 --- a/tools/run_notebooks.py +++ b/tools/run_notebooks.py @@ -25,4 +25,9 @@ import subprocess import sys -sys.exit(subprocess.call(["pytest", "--nbmake"] + glob.glob("docs/notebooks/*.ipynb"))) +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))