Skip to content

Commit

Permalink
Simplify CI workflow file by moving tutorial skip inside conftest.py
Browse files Browse the repository at this point in the history
  • Loading branch information
francesco-ballarin committed Jan 4, 2024
1 parent ceaa3c8 commit f836119
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 15 deletions.
34 changes: 20 additions & 14 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,13 @@ jobs:
git config --global --add safe.directory $PWD
git clean -xdf
- name: Update mypy configuration
if: startsWith(matrix.backend, 'none') == true
run: |
sed -i 's@\[tool\.mypy\]@[tool.mypy]\nexclude = "(^rbnicsx/backends|^tests/unit/backends)"@g' pyproject.toml
sed -i 's@ # "dolfinx",@ "dolfinx",@g' pyproject.toml
sed -i 's@ # "dolfinx.*",@ "dolfinx.*",@g' pyproject.toml
if [[ "${{ matrix.backend }}" == none* ]]; then
sed -i 's@\[tool\.mypy\]@[tool.mypy]\nexclude = "(^rbnicsx/backends|^tests/unit/backends)"@g' pyproject.toml
sed -i 's@ # "dolfinx",@ "dolfinx",@g' pyproject.toml
sed -i 's@ # "dolfinx.*",@ "dolfinx.*",@g' pyproject.toml
fi
shell: bash
- name: Run ruff on python files
run: |
python3 -m ruff .
Expand All @@ -101,9 +103,12 @@ jobs:
wget https://raw.githubusercontent.com/FEniCS/dolfinx/main/.cmake-format
find . -type f \( -name "*.cmake" -o -name "*.cmake.in" -o -name "CMakeLists.txt" \) | xargs cmake-format --check
- name: Run documentation generation
if: startsWith(matrix.backend, 'none') != true
run: |
cd docs && python3 -m sphinx -W -b html . build/html
cd docs
if [[ "${{ matrix.backend }}" == none* ]]; then
sed -i "[email protected]@@g" api.rst
fi
python3 -m sphinx -W -b html . build/html
- name: Remove source directory to ensure that package from installation directory is used
run: |
rm -rf rbnicsx
Expand Down Expand Up @@ -135,41 +140,42 @@ jobs:
python3 -m coverage combine .coverage*
python3 -m coverage report --fail-under=100 --show-missing --skip-covered
- name: Generate tutorial files
if: startsWith(matrix.backend, 'none') != true
run: |
NO_TESTS_COLLECTED=5
python3 -m pytest --ipynb-action=create-notebooks tutorials || (($?==$NO_TESTS_COLLECTED))
python3 -m pytest --ipynb-action=create-notebooks --tag-collapse tutorials || (($?==$NO_TESTS_COLLECTED))
python3 -m pytest --ipynb-action=create-notebooks --np=2 tutorials || (($?==$NO_TESTS_COLLECTED))
python3 -m pytest --ipynb-action=create-notebooks --tag-collapse --np=2 tutorials || (($?==$NO_TESTS_COLLECTED))
shell: bash
- name: Update mypy configuration
run: |
if [[ "${{ matrix.backend }}" == none* ]]; then
echo "[tool.nbqa.exclude]" >> pyproject.toml
echo "ruff = \"(^tutorials)\"" >> pyproject.toml
echo "mypy = \"(^tutorials)\"" >> pyproject.toml
fi
shell: bash
- name: Run ruff on tutorial files
if: startsWith(matrix.backend, 'none') != true
run: |
python3 -m nbqa ruff .
- name: Run isort on tutorial files
if: startsWith(matrix.backend, 'none') != true
run: |
python3 -m nbqa isort --check --diff .
- name: Run mypy on tutorial files
if: startsWith(matrix.backend, 'none') != true
run: |
python3 -m nbqa mypy .
- name: Check for stray outputs, counts and metadata in tutorial files
if: startsWith(matrix.backend, 'none') != true
uses: RBniCS/check-jupyter-metadata-action@main
with:
pattern: "tutorials/**/*.ipynb"
- name: Run tutorials (serial)
if: startsWith(matrix.backend, 'none') != true
run: |
python3 -m pytest --tag-collapse --durations=0 --durations-min=1.0 tutorials
- name: Run tutorials (parallel)
if: startsWith(matrix.backend, 'none') != true
run: |
python3 -m pytest --tag-collapse --np=2 --durations=0 --durations-min=1.0 tutorials
- name: Upload tutorials logs as an artifact in case of failure
if: startsWith(matrix.backend, 'none') != true && (failure() || cancelled())
if: failure() || cancelled()
uses: actions/upload-artifact@v3
with:
name: "tutorials-logs-${{ matrix.backend }}"
Expand Down
10 changes: 9 additions & 1 deletion tutorials/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,18 @@
"""pytest configuration file for tutorials tests."""

import nbvalx.pytest_hooks_notebooks
import pytest

pytest_addoption = nbvalx.pytest_hooks_notebooks.addoption
pytest_sessionstart = nbvalx.pytest_hooks_notebooks.sessionstart
pytest_collect_file = nbvalx.pytest_hooks_notebooks.collect_file
pytest_runtest_setup = nbvalx.pytest_hooks_notebooks.runtest_setup
pytest_runtest_makereport = nbvalx.pytest_hooks_notebooks.runtest_makereport
pytest_runtest_teardown = nbvalx.pytest_hooks_notebooks.runtest_teardown


def pytest_runtest_setup(item: pytest.File) -> None:
"""Skip tests if dolfinx is not available."""
# Do the setup as in nbvalx
nbvalx.pytest_hooks_notebooks.runtest_setup(item)
# Check dolfinx availability
pytest.importorskip("dolfinx")

0 comments on commit f836119

Please sign in to comment.