Skip to content

Commit

Permalink
WIP: adding wci 4.0 support
Browse files Browse the repository at this point in the history
  • Loading branch information
agoscinski committed Jun 27, 2024
1 parent f98d5a1 commit 3ccea00
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 7 deletions.
38 changes: 38 additions & 0 deletions .github/workflows/tests-lab-4.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Tests - lab 4

on:
push:
branches: [main]
pull_request:
# Check all PR

jobs:
tests:
runs-on: ${{ matrix.os }}
strategy:
matrix:
include:
- os: ubuntu-22.04
python-version: "3.11"

steps:
- uses: actions/checkout@v3
- name: Install Firefox
uses: browser-actions/setup-firefox@latest

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- run: pip install tox

- name: run Python tests
run: tox -e tests-lab-4

- name: run Python tests for coverage
run: tox -e coverage
- uses: codecov/codecov-action@v3
with:
files: coverage.xml
verbose: true

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ classifiers = [
dependencies = [
"ipywidgets>=8.0.0",
"numpy",
"widget_code_input",
"widget_code_input~=4.0.0",
"matplotlib",
"termcolor"
]
Expand Down
4 changes: 2 additions & 2 deletions src/scwidgets/code/_widget_code_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
import types
from typing import List, Optional

from widget_code_input import WidgetCodeInput
from widget_code_input import CodeInputWidget

from ..check import Check


class CodeInput(WidgetCodeInput):
class CodeInput(CodeInputWidget):
"""
Small wrapper around WidgetCodeInput that controls the output
"""
Expand Down
15 changes: 12 additions & 3 deletions src/scwidgets/cue/_widget_cue_figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,10 @@ def __init__(
# we close the figure so the figure is only contained in this widget
# and not shown using plt.show()
plt.close(self.figure)
elif matplotlib.backends.backend == "module://ipympl.backend_nbagg":
elif (matplotlib.backends.backend == "module://ipympl.backend_nbagg" or
matplotlib.backends.backend == "widget"):
# jupyter lab 3 uses "module://ipympl.backend_nbagg"
# jupyter lab 4 uses "widget"
with self:
self.figure.canvas.show()
else:
Expand All @@ -83,7 +86,10 @@ def clear_display(self, wait=False):
if matplotlib.backends.backend == "module://matplotlib_inline.backend_inline":
self.clear_figure()
self.clear_output(wait=wait)
elif matplotlib.backends.backend == "module://ipympl.backend_nbagg":
elif (matplotlib.backends.backend == "module://ipympl.backend_nbagg" or
matplotlib.backends.backend == "widget"):
# jupyter lab 3 uses "module://ipympl.backend_nbagg"
# jupyter lab 4 uses "widget"
self.clear_figure()
if not (wait):
self.figure.canvas.draw_idle()
Expand All @@ -100,7 +106,10 @@ def draw_display(self):
if matplotlib.backends.backend == "module://matplotlib_inline.backend_inline":
with self:
display(self.figure)
elif matplotlib.backends.backend == "module://ipympl.backend_nbagg":
elif (matplotlib.backends.backend == "module://ipympl.backend_nbagg" or
matplotlib.backends.backend == "widget"):
# jupyter lab 3 uses "module://ipympl.backend_nbagg"
# jupyter lab 4 uses "widget"
self.figure.canvas.draw_idle()
self.figure.canvas.flush_events()
else:
Expand Down
2 changes: 1 addition & 1 deletion src/scwidgets/exercise/_widget_code_exercise.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from typing import Any, Callable, Dict, List, Optional, Union

from ipywidgets import HTML, Box, HBox, HTMLMath, Layout, VBox, Widget
from widget_code_input import WidgetCodeInput
from widget_code_input import CodeInputWidget
from widget_code_input.utils import CodeValidationError

from .._utils import Formatter
Expand Down
32 changes: 32 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,38 @@ commands =
jupytext tests/notebooks/*.py --to ipynb
pytest {posargs:-v} --driver Firefox

[testenv:tests-lab-4]
description =
Tests with jupyter lab version > 4
setenv =
# this is needed to run selenium on a machine without display to do CI
SELENIUM_FIREFOX_DRIVER_ARGS = {env:SELENIUM_FIREFOX_DRIVER_ARGS:--headless}
JUPYTER_TYPE = lab
# use the jupyter config in the tox environment
# otherwise the users config is used
JUPYTER_CONFIG_DIR={envdir}/etc/jupyter
JUPYTER_DATA_DIR={envdir}/share/jupyter
deps =
pytest
pytest-html<4.0.0,
# selenium juypter notebook tests
jupyterlab~=
# fixing selenium version to have backwards-compatibility with pytest-selenium
# see https://github.com/robotframework/SeleniumLibrary/issues/1835#issuecomment-1581426365
selenium==4.9.0
pytest-selenium
jupytext==1.15.0
imageio
# we fix matplotlib for consistent image tests
matplotlib==3.7.2
numpy
scikit-image
ipympl
commands =
# converts the python files to ipython notebooks
jupytext tests/notebooks/*.py --to ipynb
pytest {posargs:-v} --driver Firefox

[testenv:tests-lab-3]
description =
Tests with jupyter lab version < 4
Expand Down

0 comments on commit 3ccea00

Please sign in to comment.