Skip to content

Commit b65db43

Browse files
FIX: Test environments with only torch or onnxruntime installed (#271)
* Drop torch and onnx variants from text extras * Test CI's in environments with either torch or onnxruntime installed * TST: import or skip * FIX: oops need to capture output of importorskip * FIX: dep * DOC: Note for Megnet users * FIX, DOC: flaky link * Revert "FIX, DOC: flaky link" This reverts commit 49d678f. * TST: Add backend job * Update doc/install.rst Co-authored-by: Mathieu Scheltienne <mathieu.scheltienne@gmail.com> * FIX, STY: Flakes --------- Co-authored-by: Mathieu Scheltienne <mathieu.scheltienne@gmail.com>
1 parent 4d525b8 commit b65db43

File tree

6 files changed

+47
-7
lines changed

6 files changed

+47
-7
lines changed

.github/workflows/pytest.yaml

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ jobs:
3434
- name: Install package
3535
run: |
3636
python -m pip install --progress-bar off --upgrade pip setuptools
37-
python -m pip install --progress-bar off .[test]
37+
python -m pip install --progress-bar off ".[test,torch,onnx]"
3838
- run: mne_icalabel-sys_info --developer
3939
- run: pytest mne_icalabel --cov=mne_icalabel --cov-report=xml --cov-config=pyproject.toml
4040
- uses: codecov/codecov-action@v5
@@ -64,7 +64,7 @@ jobs:
6464
- name: Install dependencies
6565
run: |
6666
python -m pip install --progress-bar off --upgrade pip setuptools
67-
python -m pip install --progress-bar off .[test]
67+
python -m pip install --progress-bar off ".[test,torch,onnx]"
6868
python -m pip install --progress-bar off --upgrade git+https://github.com/mne-tools/mne-python
6969
python -m pip install --progress-bar off --upgrade git+https://github.com/mne-tools/mne-bids
7070
python -m pip install --progress-bar off --upgrade --pre --only-binary :all: -i https://pypi.anaconda.org/scientific-python-nightly-wheels/simple --timeout=180 numpy scipy matplotlib
@@ -77,3 +77,35 @@ jobs:
7777
name: codecov-umbrella # optional
7878
token: ${{ secrets.CODECOV_TOKEN }}
7979
verbose: true # optional (default = false)
80+
81+
pytest-backend:
82+
timeout-minutes: 30
83+
strategy:
84+
fail-fast: false
85+
matrix:
86+
os: [ubuntu]
87+
backend: ["torch", "onnx"]
88+
python-version: ["3.12"]
89+
name: ${{ matrix.os }} - ${{ matrix.backend }} backend - py${{ matrix.python-version }}
90+
runs-on: ${{ matrix.os }}-latest
91+
steps:
92+
- uses: actions/checkout@v5
93+
- uses: actions/setup-python@v6
94+
with:
95+
python-version: ${{ matrix.python-version }}
96+
- uses: pyvista/setup-headless-display-action@main
97+
with:
98+
qt: true
99+
- name: Install package
100+
run: |
101+
python -m pip install --progress-bar off --upgrade pip setuptools
102+
python -m pip install --progress-bar off ".[test,${{ matrix.backend }}]";
103+
- run: mne_icalabel-sys_info --developer
104+
- run: pytest mne_icalabel --cov=mne_icalabel --cov-report=xml --cov-config=pyproject.toml
105+
- uses: codecov/codecov-action@v5
106+
with:
107+
files: ./coverage.xml
108+
flags: unittests # optional
109+
name: codecov-umbrella # optional
110+
token: ${{ secrets.CODECOV_TOKEN }}
111+
verbose: true # optional (default = false)

doc/install.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@ Methods
4343
4444
pip install torch
4545
pip install onnxruntime
46+
47+
.. note::
48+
49+
If you are working with MEG data and plan to use the MEGnet model, e.g.
50+
:func:`mne_icalabel.megnet.megnet_label_components`, you *must* install
51+
``onnxruntime``, and do not need to install ``torch``.
4652

4753
Additional dependencies can be installed with different keywords:
4854

mne_icalabel/iclabel/network/tests/test_network.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@
22

33
import numpy as np
44
import pytest
5-
import torch
65
from scipy.io import loadmat
76

87
from mne_icalabel.datasets import icalabel
98
from mne_icalabel.iclabel.network.utils import _format_input
109
from mne_icalabel.utils._tests import requires_module
1110

11+
torch = pytest.importorskip("torch")
12+
1213
dataset_path = icalabel.data_path() / "iclabel"
1314

1415

mne_icalabel/megnet/label_components.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@
44
from typing import TYPE_CHECKING
55

66
import numpy as np
7-
import onnxruntime as ort
87
from mne.io import BaseRaw
98
from mne.preprocessing import ICA
109

10+
from ..utils._imports import import_optional_dependency
1111
from .features import get_megnet_features
1212

1313
if TYPE_CHECKING:
14+
import onnxruntime as ort
1415
from numpy.typing import NDArray
1516

1617
_MODEL_PATH: str = files("mne_icalabel.megnet") / "assets" / "megnet.onnx"
@@ -43,6 +44,7 @@ def megnet_label_components(raw: BaseRaw, ica: ICA) -> NDArray:
4344
----------
4445
.. footbibliography::
4546
"""
47+
ort = import_optional_dependency("onnxruntime")
4648
time_series, topomaps = get_megnet_features(raw, ica)
4749

4850
# sanity-checks

mne_icalabel/megnet/tests/test_label_components.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
import mne
77
import numpy as np
8-
import onnxruntime as ort
98
import pytest
109
from mne.io.base import BaseRaw
1110
from mne.preprocessing.ica import ICA
@@ -17,6 +16,8 @@
1716
megnet_label_components,
1817
)
1918

19+
ort = pytest.importorskip("onnxruntime")
20+
2021
if TYPE_CHECKING:
2122
from mne.io import BaseRaw
2223
from mne.preprocessing import ICA

pyproject.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,6 @@ test = [
113113
'mne-bids>=0.14',
114114
'mne-icalabel[gui]',
115115
'mne-icalabel[ica]',
116-
'mne-icalabel[onnx]',
117-
'mne-icalabel[torch]',
118116
'pandas',
119117
'pymatreader',
120118
'PyQt6',

0 commit comments

Comments
 (0)