Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

[maint] Fix CI (GitHub actions workflow and tox.ini) #55

Merged
merged 15 commits into from
Sep 23, 2024
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
27 changes: 11 additions & 16 deletions .github/workflows/test_and_deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,26 @@ on:
- main
workflow_dispatch:

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
test:
name: ${{ matrix.platform }} ${{ matrix.python-version }}
runs-on: ${{ matrix.platform }}
defaults:
run:
shell: bash -l {0}
strategy:
fail-fast: false
matrix:
platform: [ubuntu-latest]#, macos-latest, windows-latest]
python-version: ["3.9", "3.10", "3.11"]
backend: [pyqt5]
platform: [ubuntu-latest, macos-latest, windows-latest]
python-version: ["3.9", "3.10", "3.11", "3.12"]

steps:
- uses: actions/checkout@v4
- uses: conda-incubator/setup-miniconda@v2

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
miniconda-version: "latest"
channels: conda-forge
channel-priority: strict
python-version: ${{ matrix.python-version }}

- uses: tlambert03/setup-qt-libs@v1
Expand All @@ -51,18 +50,14 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install --upgrade setuptools tox tox-conda tox-gh-actions
python -m pip install --upgrade setuptools tox tox-gh-actions

- name: Test with tox
uses: aganders3/headless-gui@v1.2
uses: aganders3/headless-gui@v2
with:
shell: bash -el {0}
run: python -m tox
env:
PLATFORM: ${{ matrix.platform }}
PYTHON: ${{ matrix.python-version }}
PYVISTA_OFF_SCREEN: True
BACKEND: ${{ matrix.backend }}

- name: Codecov
uses: codecov/codecov-action@v3
Expand Down
31 changes: 16 additions & 15 deletions tests/test_plugin.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
import os
import sys
from pathlib import Path
from math import isclose
from typing import Callable

import cellpose_napari
import napari
import pytest
import torch # for ubuntu tests on CI, see https://github.com/pytorch/pytorch/issues/75912
from cellpose_napari._dock_widget import widget_wrapper

# this is your plugin name declared in your napari.plugins entry point
PLUGIN_NAME = "cellpose-napari"
Expand All @@ -17,6 +14,14 @@

SAMPLE = Path(__file__).parent / "sample.tif"

@pytest.fixture(autouse=True)
def patch_mps_on_CI(monkeypatch):
# https://github.com/actions/runner-images/issues/9918
if os.getenv('CI'):
monkeypatch.setattr("torch.backends.mps.is_available", lambda: False)
monkeypatch.setattr("cellpose.core.assign_device", lambda **kwargs: (torch.device("cpu"), False))


@pytest.fixture
def viewer_widget(make_napari_viewer: Callable[..., napari.Viewer]):
viewer = make_napari_viewer()
Expand All @@ -32,11 +37,7 @@ def test_basic_function(qtbot, viewer_widget):
viewer.open_sample(PLUGIN_NAME, 'rgb_2D')
viewer.layers[0].data = viewer.layers[0].data[0:128, 0:128]

#if os.getenv("CI"):
# return
# actually running cellpose like this takes too long and always timesout on CI
# need to figure out better strategy

widget.model_type.value = "cyto3"
widget() # run segmentation with all default parameters

def check_widget():
Expand All @@ -47,10 +48,9 @@ def check_widget():
assert len(viewer.layers) == 5
assert "cp_masks" in viewer.layers[-1].name

# check that the segmentation was proper, should yield 11 cells
# check that the segmentation was proper, cyto3 yields 10 cells
assert viewer.layers[-1].data.max() == 10

@pytest.mark.skipif(sys.platform.startswith('linux'), reason="ubuntu stalls with two cellpose tests")
def test_compute_diameter(qtbot, viewer_widget):
viewer, widget = viewer_widget
viewer.open_sample(PLUGIN_NAME, 'rgb_2D')
Expand All @@ -63,16 +63,17 @@ def test_compute_diameter(qtbot, viewer_widget):
with qtbot.waitSignal(widget.diameter.changed, timeout=60_000) as blocker:
widget.compute_diameter_button.changed(None)

assert isclose(float(widget.diameter.value), 24.1, abs_tol=10**-1)
# local on macOS with MPS, get 20.37, with CPU-only it's 20.83, same as CI
# so choosing a target that works for both
assert isclose(float(widget.diameter.value), 20.6, abs_tol=0.3)

@pytest.mark.skipif(sys.platform.startswith('linux'), reason="ubuntu stalls with >1 cellpose tests")
def test_3D_segmentation(qtbot, viewer_widget):
viewer, widget = viewer_widget
viewer.open_sample(PLUGIN_NAME, 'rgb_3D')

# set 3D processing
widget.process_3D.value = True

widget.model_type.value = "cyto3"
widget() # run segmentation with all default parameters

def check_widget():
Expand All @@ -83,5 +84,5 @@ def check_widget():
assert len(viewer.layers) == 5
assert "cp_masks" in viewer.layers[-1].name

# check that the segmentation was proper, should yield 7 cells
assert viewer.layers[-1].data.max() == 7
# check that the segmentation was proper, `cyto3` should yield 9 cells
assert viewer.layers[-1].data.max() == 9
5 changes: 3 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
# For more information about tox, see https://tox.readthedocs.io/en/latest/
[tox]
envlist = py{38,39,310}-{linux,macos,windows}
envlist = py{39,310,311,312}-{linux,macos,windows}
isolated_build=true
toxworkdir = /tmp/.tox

[gh-actions]
python =
3.8: py38
3.9: py39
3.10: py310
3.11: py311
3.12: py312

[gh-actions:env]
PLATFORM =
Expand Down
Loading