Skip to content
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
13 changes: 7 additions & 6 deletions .github/workflows/publish-to-pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@ jobs:
run: |
python -m pip install --upgrade pip
pip install setuptools wheel twine build
pip install -e .
# pip install PySide6
# pip install .[test]
#- name: Test core with pytest
# run: |
# pytest spikeinterface-gui
pip install -e .[test] ./plugin_example
- name: Install Qt system libraries
run: sudo apt-get update && sudo apt-get install -y libegl1 libgl1 libxkbcommon0
- name: Test with pytest
env:
QT_QPA_PLATFORM: offscreen
run: pytest spikeinterface_gui/tests -v
- name: Package and Upload
env:
TWINE_USERNAME: __token__
Expand Down
38 changes: 38 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Tests

on:
pull_request:
push:
branches:
- main

concurrency:
# one run per PR (or per branch for pushes): a new push cancels the run in progress
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
test:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Set up Python 3.12
uses: actions/setup-python@v5
with:
python-version: 3.12
- name: Install Qt system libraries
run: sudo apt-get update && sudo apt-get install -y libegl1 libgl1 libxkbcommon0
- name: Install package, test dependencies and the plugin example
run: |
python -m pip install --upgrade pip
pip install -e .[test] ./plugin_example
- name: Cache test datasets
uses: actions/cache@v4
with:
path: spikeinterface_gui/tests/datasets
key: test-datasets-${{ hashFiles('spikeinterface_gui/tests/testingtools.py') }}
- name: Test with pytest
env:
QT_QPA_PLATFORM: offscreen
run: pytest spikeinterface_gui/tests -v
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
spikeinterface_gui/tests/*/*
my_dataset/*
spikeinterface_gui/tests/datasets/

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

magnifico

comparison_scripts/


Expand Down
2 changes: 1 addition & 1 deletion .readthedocs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version: 2
build:
os: "ubuntu-24.04"
tools:
python: "3.10"
python: "3.12"
commands:
- asdf plugin add uv
- asdf install uv latest
Expand Down
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,16 @@ pip install .

You'll then need to install the appropriate backends yourself (`pyqtgraph` and `PySide6` or `PyQt5` for the desktop; `panel` and `bokeh` for web).

To test that your installation works, you can run any script in our `test` directory. This will run the GUI on some synthetic test data. E.g. from the `spikeinterface-gui` folder, you could run
To test that your installation works, you can launch the GUI on some synthetic test data, built in `spikeinterface_gui/tests/datasets` on first use. From the `spikeinterface-gui` folder:

```bash
python spikeinterface_gui/tests/test_mainwindow_qt.py
python spikeinterface_gui/tests/run_gui.py # desktop
python spikeinterface_gui/tests/run_gui.py --mode web # web
python spikeinterface_gui/tests/run_gui.py --comparison # compare two sortings
```

Run `python spikeinterface_gui/tests/run_gui.py --help` for all options. To run the test suite: `pip install -e .[test]` then `pytest`.

# Main usage

The main idea is to make visible one or several units and visually inspect if they should be merged or removed.
Expand Down Expand Up @@ -421,4 +425,4 @@ Main authors and maintainers:

* desktop side: Samuel Garcia, CNRS, Lyon, France
* web side: Alessio Paolo Buccino, Allen Institute for Neural Dynamics, Seattle, USA
* maintainer: Chris Halcrow, University of Edinburgh, Scotland, UK
* maintainer: Chris Halcrow, Sainsbury Wellcome Centre, London, UK
6 changes: 6 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,19 @@ web = [
test = [
"pytest",
"PySide6",
"pyqtgraph",
"panel",
"bokeh",
]

docs = [
"sphinx>=5.0",
"sphinx_rtd_theme",
]

[tool.pytest.ini_options]
testpaths = ["spikeinterface_gui/tests"]

[tool.codespell]
# Ref: https://github.com/codespell-project/codespell#using-a-config-file
skip = '.git*,pyproject.toml'
Expand Down
60 changes: 60 additions & 0 deletions spikeinterface_gui/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import os

# headless Qt, for the tests and the CI; set before anything imports Qt
os.environ.setdefault("QT_QPA_PLATFORM", "offscreen")

import pytest

import spikeinterface.full as si

from spikeinterface_gui.tests.testingtools import (
get_dataset_folder, make_curation_dict, prepare_analyzer_for_gui, set_comparison_labels,
)


@pytest.fixture(scope="session")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Code anarchists are very welcome. So in this mess, persona non grata: pre-commit, black, pytest fixture, ..."

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

he lost a battle, but not the war

def analyzer_folder():
return get_dataset_folder("small")


@pytest.fixture(scope="session")
def comparison_folder():
return get_dataset_folder("small", comparison=True)


@pytest.fixture(scope="session")
def qapp():
pytest.importorskip("PySide6")
pytest.importorskip("pyqtgraph")
from spikeinterface_gui.myqt import mkQApp
return mkQApp()


def _skip_if_backend_missing(backend):
if backend == "qt":
pytest.importorskip("PySide6")
pytest.importorskip("pyqtgraph")
else:
pytest.importorskip("panel")


def load_controller(analyzer_folder, backend):
"""A Controller with curation and events, so every view of the main GUI is possible."""
from spikeinterface_gui.controller import Controller

_skip_if_backend_missing(backend)
analyzer = si.load_sorting_analyzer(analyzer_folder / "sorting_analyzer")
extra_unit_properties, events = prepare_analyzer_for_gui(analyzer, events="times", seed=0)
return Controller(analyzer, backend=backend, curation=True, curation_data=make_curation_dict(analyzer),
extra_unit_properties=extra_unit_properties, events=events)


def load_comparison_controller(comparison_folder, backend):
from spikeinterface_gui.controllercomparison import ControllerComparison

_skip_if_backend_missing(backend)
analyzer1 = si.load_sorting_analyzer(comparison_folder / "sorting_analyzer_1")
analyzer2 = si.load_sorting_analyzer(comparison_folder / "sorting_analyzer_2")
set_comparison_labels(analyzer1, analyzer2)
return ControllerComparison(analyzer1, analyzer2, analyzer1_name="sorter1", analyzer2_name="sorter2",
backend=backend)
45 changes: 0 additions & 45 deletions spikeinterface_gui/tests/debug_panel_embedded.py

This file was deleted.

86 changes: 0 additions & 86 deletions spikeinterface_gui/tests/debug_views.py

This file was deleted.

73 changes: 73 additions & 0 deletions spikeinterface_gui/tests/run_gui.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
"""
Launch the GUI on a test dataset from tests/datasets, built on first use.

python run_gui.py # desktop, small dataset, with curation
python run_gui.py --mode web --events samples
python run_gui.py --comparison --mode web
python run_gui.py --launcher
panel serve run_gui.py --autoreload # web, default options
"""
from argparse import ArgumentParser

from spikeinterface import load_sorting_analyzer

from spikeinterface_gui import run_mainwindow, run_mainwindow_comparison, run_launcher
from spikeinterface_gui.tests.testingtools import (
DATASETS_FOLDER, get_dataset_folder, make_curation_dict, prepare_analyzer_for_gui, set_comparison_labels,
)

parser = ArgumentParser(description=__doc__.split("\n\n")[0])
parser.add_argument('--mode', default="desktop", choices=["desktop", "web"])
parser.add_argument('--comparison', action="store_true", help='Compare two analyzers')
parser.add_argument('--dataset', default="small",
help='small | medium-split | multiprobe | big, or small | medium with --comparison')
parser.add_argument('--regenerate', action="store_true", help='Rebuild the dataset')
parser.add_argument('--events', choices=["times", "samples"], help='Simulate events, given as times or samples')
parser.add_argument('--no-curation', action="store_true", help='Disable curation')
parser.add_argument('--iterative', action="store_true", help='Run iterative curation')
parser.add_argument('--layout', default="default", help='Layout preset')
parser.add_argument('--lazy', action="store_true", help='Lazy load')
parser.add_argument('--port', default=0, type=int, help='Port for the web server')
parser.add_argument('--no-start', action="store_true", help='Do not start the app')
parser.add_argument('--launcher', action="store_true", help='Open the launcher on all datasets in tests/datasets')


def main(args, start_app=True):
if args.launcher:
return run_launcher(mode=args.mode, root_folder=DATASETS_FOLDER, port=args.port, verbose=True)

folder = get_dataset_folder(args.dataset, comparison=args.comparison, regenerate=args.regenerate)

if args.comparison:
analyzer1 = load_sorting_analyzer(folder / "sorting_analyzer_1", lazy=args.lazy)
analyzer2 = load_sorting_analyzer(folder / "sorting_analyzer_2", lazy=args.lazy)
set_comparison_labels(analyzer1, analyzer2)
return run_mainwindow_comparison(
analyzer1, analyzer2, analyzer1_name="sorter1", analyzer2_name="sorter2",
mode=args.mode, start_app=start_app, verbose=True, port=args.port,
)

analyzer = load_sorting_analyzer(folder / "sorting_analyzer", load_extensions=False, lazy=args.lazy)
extra_unit_properties, events = prepare_analyzer_for_gui(analyzer, events=args.events)
curation = not args.no_curation
return run_mainwindow(
analyzer,
mode=args.mode,
start_app=start_app,
verbose=True,
curation=curation,
curation_dict=make_curation_dict(analyzer) if curation else None,
iterative_curation=args.iterative,
extra_unit_properties=extra_unit_properties,
layout_preset=args.layout,
events=events,
port=args.port,
)


if __name__ == '__main__':
args = parser.parse_args()
win = main(args, start_app=not args.no_start)
elif __name__.startswith("bokeh"):
# panel serve: the window registers itself as servable
win = main(parser.parse_args(["--mode", "web"]), start_app=False)
Loading
Loading