Skip to content

Commit 5df6b6b

Browse files
committed
Merge branch 'main' into color-histogram-bars
2 parents 5b87710 + 5e59bd3 commit 5df6b6b

21 files changed

+46
-52
lines changed

.github/workflows/test_and_deploy.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
fail-fast: false
2121
matrix:
2222
platform: [ubuntu-latest, macos-latest, windows-latest]
23-
python-version: ['3.8', '3.9', '3.10', '3.11']
23+
python-version: ['3.9', '3.10', '3.11']
2424

2525
steps:
2626
- uses: actions/checkout@v3

.pre-commit-config.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
repos:
22
- repo: https://github.com/pre-commit/pre-commit-hooks
3-
rev: v4.4.0
3+
rev: v4.5.0
44
hooks:
55
- id: check-docstring-first
66
- id: end-of-file-fixer
@@ -17,14 +17,14 @@ repos:
1717
- id: napari-plugin-checks
1818

1919
- repo: https://github.com/pre-commit/mirrors-mypy
20-
rev: v1.5.1
20+
rev: v1.6.0
2121
hooks:
2222
- id: mypy
23-
additional_dependencies: [numpy, matplotlib<3.8]
23+
additional_dependencies: [numpy, matplotlib]
2424

2525
- repo: https://github.com/astral-sh/ruff-pre-commit
2626
# Ruff version.
27-
rev: 'v0.0.288'
27+
rev: 'v0.0.292'
2828
hooks:
2929
- id: ruff
3030

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ profile = "black"
2323
line_length = 79
2424

2525
[tool.ruff]
26-
target-version = "py38"
26+
target-version = "py39"
2727
select = ["I", "UP", "F", "E", "W", "D"]
2828
ignore = [
2929
"D100", # Missing docstring in public module
@@ -45,7 +45,7 @@ fix = true
4545
convention = "numpy"
4646

4747
[tool.mypy]
48-
python_version = "3.8"
48+
python_version = "3.9"
4949
# Block below are checks that form part of mypy 'strict' mode
5050
warn_unused_configs = true
5151
warn_redundant_casts = true

setup.cfg

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ project_urls =
2727
[options]
2828
packages = find:
2929
install_requires =
30-
matplotlib<3.8
30+
matplotlib
3131
napari
3232
numpy
3333
tinycss2
34-
python_requires = >=3.8
34+
python_requires = >=3.9
3535
include_package_data = True
3636
package_dir =
3737
=src
@@ -49,6 +49,7 @@ napari.manifest =
4949
docs =
5050
napari[all]==0.4.17
5151
numpydoc
52+
pydantic<2
5253
pydata-sphinx-theme
5354
qtgallery
5455
sphinx

src/napari_matplotlib/base.py

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import os
22
from pathlib import Path
3-
from typing import List, Optional, Tuple
3+
from typing import Optional
44

55
import matplotlib
66
import matplotlib.style as mplstyle
77
import napari
8-
from matplotlib.backends.backend_qtagg import (
9-
FigureCanvas,
8+
from matplotlib.backends.backend_qtagg import ( # type: ignore[attr-defined]
9+
FigureCanvasQTAgg,
1010
NavigationToolbar2QT,
1111
)
1212
from matplotlib.figure import Figure
@@ -49,12 +49,10 @@ def __init__(
4949

5050
# Sets figure.* style
5151
with mplstyle.context(self.mpl_style_sheet_path):
52-
self.canvas = FigureCanvas()
52+
self.canvas = FigureCanvasQTAgg() # type: ignore[no-untyped-call]
5353

5454
self.canvas.figure.set_layout_engine("constrained")
55-
self.toolbar = NapariNavigationToolbar(
56-
self.canvas, parent=self
57-
) # type: ignore[no-untyped-call]
55+
self.toolbar = NapariNavigationToolbar(self.canvas, parent=self)
5856
self._replace_toolbar_icons()
5957
# callback to update when napari theme changed
6058
# TODO: this isn't working completely (see issue #140)
@@ -97,7 +95,7 @@ def add_single_axes(self) -> None:
9795
# Sets axes.* style.
9896
# Does not set any text styling set by axes.* keys
9997
with mplstyle.context(self.mpl_style_sheet_path):
100-
self.axes = self.figure.subplots()
98+
self.axes = self.figure.add_subplot()
10199

102100
def _on_napari_theme_changed(self) -> None:
103101
"""
@@ -184,7 +182,7 @@ class NapariMPLWidget(BaseNapariMPLWidget):
184182
#: Number of layers taken as input
185183
n_layers_input = Interval(None, None)
186184
#: Type of layer taken as input
187-
input_layer_types: Tuple[napari.layers.Layer, ...] = (napari.layers.Layer,)
185+
input_layer_types: tuple[napari.layers.Layer, ...] = (napari.layers.Layer,)
188186

189187
def __init__(
190188
self,
@@ -193,7 +191,7 @@ def __init__(
193191
):
194192
super().__init__(napari_viewer=napari_viewer, parent=parent)
195193
self._setup_callbacks()
196-
self.layers: List[napari.layers.Layer] = []
194+
self.layers: list[napari.layers.Layer] = []
197195

198196
helper_text = self.n_layers_input._helper_text
199197
if helper_text is not None:
@@ -260,7 +258,7 @@ def _draw(self) -> None:
260258
isinstance(layer, self.input_layer_types) for layer in self.layers
261259
):
262260
self.draw()
263-
self.canvas.draw()
261+
self.canvas.draw() # type: ignore[no-untyped-call]
264262

265263
def clear(self) -> None:
266264
"""
@@ -309,8 +307,8 @@ def clear(self) -> None:
309307
class NapariNavigationToolbar(NavigationToolbar2QT):
310308
"""Custom Toolbar style for Napari."""
311309

312-
def __init__(self, *args, **kwargs): # type: ignore[no-untyped-def]
313-
super().__init__(*args, **kwargs)
310+
def __init__(self, *args, **kwargs) -> None: # type: ignore[no-untyped-def]
311+
super().__init__(*args, **kwargs) # type: ignore[no-untyped-call]
314312
self.setIconSize(
315313
from_napari_css_get_size_of(
316314
"QtViewerPushButton", fallback=(28, 28)
@@ -319,7 +317,7 @@ def __init__(self, *args, **kwargs): # type: ignore[no-untyped-def]
319317

320318
def _update_buttons_checked(self) -> None:
321319
"""Update toggle tool icons when selected/unselected."""
322-
super()._update_buttons_checked()
320+
super()._update_buttons_checked() # type: ignore[no-untyped-call]
323321
icon_dir = self.parentWidget()._get_path_to_icon()
324322

325323
# changes pan/zoom icons depending on state (checked or not)

src/napari_matplotlib/histogram.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Any, List, Optional, Tuple
1+
from typing import Any, Optional
22

33
import napari
44
import numpy as np
@@ -107,7 +107,7 @@ def _set_axis_keys(self, x_axis_key: str) -> None:
107107
self._x_axis_key = x_axis_key
108108
self._draw()
109109

110-
def _get_valid_axis_keys(self) -> List[str]:
110+
def _get_valid_axis_keys(self) -> list[str]:
111111
"""
112112
Get the valid axis keys from the layer FeatureTable.
113113
@@ -122,7 +122,7 @@ def _get_valid_axis_keys(self) -> List[str]:
122122
else:
123123
return self.layers[0].features.keys()
124124

125-
def _get_data(self) -> Tuple[Optional[npt.NDArray[Any]], str]:
125+
def _get_data(self) -> tuple[Optional[npt.NDArray[Any]], str]:
126126
"""Get the plot data.
127127
128128
Returns

src/napari_matplotlib/scatter.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Any, Dict, List, Optional, Tuple, Union
1+
from typing import Any, Optional, Union
22

33
import napari
44
import numpy.typing as npt
@@ -40,7 +40,7 @@ def draw(self) -> None:
4040
self.axes.set_xlabel(x_axis_name)
4141
self.axes.set_ylabel(y_axis_name)
4242

43-
def _get_data(self) -> Tuple[npt.NDArray[Any], npt.NDArray[Any], str, str]:
43+
def _get_data(self) -> tuple[npt.NDArray[Any], npt.NDArray[Any], str, str]:
4444
"""
4545
Get the plot data.
4646
@@ -67,7 +67,7 @@ class ScatterWidget(ScatterBaseWidget):
6767
n_layers_input = Interval(2, 2)
6868
input_layer_types = (napari.layers.Image,)
6969

70-
def _get_data(self) -> Tuple[npt.NDArray[Any], npt.NDArray[Any], str, str]:
70+
def _get_data(self) -> tuple[npt.NDArray[Any], npt.NDArray[Any], str, str]:
7171
"""
7272
Get the plot data.
7373
@@ -106,7 +106,7 @@ def __init__(
106106

107107
self.layout().addLayout(QVBoxLayout())
108108

109-
self._selectors: Dict[str, QComboBox] = {}
109+
self._selectors: dict[str, QComboBox] = {}
110110
for dim in ["x", "y"]:
111111
self._selectors[dim] = QComboBox()
112112
# Re-draw when combo boxes are updated
@@ -147,7 +147,7 @@ def y_axis_key(self, key: str) -> None:
147147
self._selectors["y"].setCurrentText(key)
148148
self._draw()
149149

150-
def _get_valid_axis_keys(self) -> List[str]:
150+
def _get_valid_axis_keys(self) -> list[str]:
151151
"""
152152
Get the valid axis keys from the layer FeatureTable.
153153
@@ -186,7 +186,7 @@ def draw(self) -> None:
186186
if self._ready_to_scatter():
187187
super().draw()
188188

189-
def _get_data(self) -> Tuple[npt.NDArray[Any], npt.NDArray[Any], str, str]:
189+
def _get_data(self) -> tuple[npt.NDArray[Any], npt.NDArray[Any], str, str]:
190190
"""
191191
Get the plot data from the ``features`` attribute of the first
192192
selected layer.

src/napari_matplotlib/slice.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Any, List, Optional, Tuple
1+
from typing import Any, Optional
22

33
import matplotlib.ticker as mticker
44
import napari
@@ -99,7 +99,7 @@ def current_dim_index(self) -> int:
9999
return self._dim_names.index(self.current_dim_name)
100100

101101
@property
102-
def _dim_names(self) -> List[str]:
102+
def _dim_names(self) -> list[str]:
103103
"""
104104
List of dimension names. This is a property as it varies depending on the
105105
dimensionality of the currently selected data.
@@ -111,7 +111,7 @@ def _dim_names(self) -> List[str]:
111111
else:
112112
raise RuntimeError("Don't know how to handle ndim != 2 or 3")
113113

114-
def _get_xy(self) -> Tuple[npt.NDArray[Any], npt.NDArray[Any]]:
114+
def _get_xy(self) -> tuple[npt.NDArray[Any], npt.NDArray[Any]]:
115115
"""
116116
Get data for plotting.
117117
"""
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading

src/napari_matplotlib/tests/scatter/test_scatter_features.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from copy import deepcopy
2-
from typing import Any, Dict, Tuple
2+
from typing import Any
33

44
import numpy as np
55
import numpy.typing as npt
@@ -34,7 +34,7 @@ def test_features_scatter_widget_2D(
3434

3535

3636
def make_labels_layer_with_features() -> (
37-
Tuple[npt.NDArray[np.uint16], Dict[str, Any]]
37+
tuple[npt.NDArray[np.uint16], dict[str, Any]]
3838
):
3939
label_image: npt.NDArray[np.uint16] = np.zeros((100, 100), dtype=np.uint16)
4040
for label_value, start_index in enumerate([10, 30, 50], start=1):

src/napari_matplotlib/tests/test_layer_changes.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from copy import deepcopy
2-
from typing import Any, Dict, Tuple, Type
2+
from typing import Any
33

44
import numpy as np
55
import numpy.typing as npt
@@ -61,8 +61,8 @@ def test_change_features_layer(
6161

6262
def assert_features_plot_changes(
6363
viewer: Viewer,
64-
widget_cls: Type[NapariMPLWidget],
65-
data: Tuple[npt.NDArray[np.generic], Dict[str, Any]],
64+
widget_cls: type[NapariMPLWidget],
65+
data: tuple[npt.NDArray[np.generic], dict[str, Any]],
6666
) -> None:
6767
"""
6868
When the selected layer is changed, make sure the plot generated

src/napari_matplotlib/tests/test_theme.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,6 @@ def test_custom_stylesheet(make_napari_viewer, image_data):
187187
assert widget.figure.patch.get_facecolor() == to_rgba("#fdf6e3")
188188
for gridline in ax.get_xgridlines() + ax.get_ygridlines():
189189
assert gridline.get_visible() is True
190-
assert gridline.get_color() == "#fdf6e3"
190+
assert gridline.get_color() == "#b0b0b0"
191191
finally:
192192
os.remove(style_sheet_path)

src/napari_matplotlib/util.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import List, Optional, Tuple, Union
1+
from typing import Optional, Union
22
from warnings import warn
33

44
import napari.qt
@@ -76,7 +76,7 @@ def _helper_text(self) -> Optional[str]:
7676
return helper_text
7777

7878

79-
def _has_id(nodes: List[tinycss2.ast.Node], id_name: str) -> bool:
79+
def _has_id(nodes: list[tinycss2.ast.Node], id_name: str) -> bool:
8080
"""
8181
Is `id_name` in IdentTokens in the list of CSS `nodes`?
8282
"""
@@ -86,7 +86,7 @@ def _has_id(nodes: List[tinycss2.ast.Node], id_name: str) -> bool:
8686

8787

8888
def _get_dimension(
89-
nodes: List[tinycss2.ast.Node], id_name: str
89+
nodes: list[tinycss2.ast.Node], id_name: str
9090
) -> Union[int, None]:
9191
"""
9292
Get the value of the DimensionToken for the IdentToken `id_name`.
@@ -108,7 +108,7 @@ def _get_dimension(
108108

109109

110110
def from_napari_css_get_size_of(
111-
qt_element_name: str, fallback: Tuple[int, int]
111+
qt_element_name: str, fallback: tuple[int, int]
112112
) -> QSize:
113113
"""
114114
Get the size of `qt_element_name` from napari's current stylesheet.

tox.ini

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,14 @@
11
[tox]
2-
envlist = py{38,39,310,311}
2+
envlist = py{39,310,311}
33
isolated_build = true
44

55
[gh-actions]
66
python =
7-
3.8: py38
87
3.9: py39
98
3.10: py310
9+
3.11: py311
1010

1111
[testenv]
1212
extras = testing
13-
allowlist_externals =
14-
cp
15-
ls
1613
commands =
17-
cp -R {toxinidir}/src/napari_matplotlib/tests/baseline {envdir}/baseline
18-
ls {toxinidir}/src/napari_matplotlib/tests/baseline
1914
python -m pytest --mpl --mpl-generate-summary=html --mpl-results-path={toxinidir}/reports -v --color=yes --cov=napari_matplotlib --cov-report=xml

0 commit comments

Comments
 (0)