Skip to content

Commit

Permalink
Fix plugin for napari >=0.5.5
Browse files Browse the repository at this point in the history
  • Loading branch information
loicsauteur committed Jan 3, 2025
1 parent b792df0 commit 21bbda9
Show file tree
Hide file tree
Showing 15 changed files with 202 additions and 170 deletions.
22 changes: 0 additions & 22 deletions .github/workflows/plugin_preview.yml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,17 @@ jobs:
test:
name: ${{ matrix.platform }} py${{ matrix.python-version }}
runs-on: ${{ matrix.platform }}
timeout-minutes: 30
strategy:
matrix:
platform: [ubuntu-latest, windows-latest, macos-latest]
python-version: ['3.8', '3.9', '3.10']
python-version: ["3.9", "3.10", "3.11", "3.12"]

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

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

Expand All @@ -54,7 +55,7 @@ jobs:

# this runs the platform-specific tests declared in tox.ini
- name: Test with tox
uses: aganders3/headless-gui@v1
uses: aganders3/headless-gui@v2
with:
run: python -m tox
env:
Expand All @@ -71,9 +72,9 @@ jobs:
runs-on: ubuntu-latest
if: contains(github.ref, 'tags')
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: "3.x"
- name: Install dependencies
Expand Down
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,3 @@ venv/

# written by setuptools_scm
**/_version.py

5 changes: 2 additions & 3 deletions .napari-hub/DESCRIPTION.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,12 @@ Channels are considered a dimension.
1. Best, an image with the same dimension as you labels layer should have
2. e.g. ``File > Open Sample > napari > Binary Blobs (3D)``
3. Add (or load) a labels layer
4. Start the plugin ``Plugins > napari-annotator: Annotator``
4. Start the plugin ``Plugins > Annotator (Annotator)``
5. Make sure the labels layer is selected
6. Start drawing

#### Known limitations
1. Lag when drawing (see [GitHub README](https://github.com/loicsauteur/napari-annotator) for more info).
2. Maximum 255 labels supported (see [GitHub README](https://github.com/loicsauteur/napari-annotator) for more info).
1. Maximum 20'000 labels are supported.

# Getting Help

Expand Down
32 changes: 9 additions & 23 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,41 +1,27 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.2.0
rev: v5.0.0
hooks:
- id: check-docstring-first
- id: end-of-file-fixer
- id: trailing-whitespace
exclude: ^\.napari-hub/.*
- repo: https://github.com/PyCQA/isort
rev: 5.10.1
- id: check-yaml # checks for correct yaml syntax for github actions ex.
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.8.5
hooks:
- id: isort
- repo: https://github.com/asottile/pyupgrade
rev: v2.32.1
hooks:
- id: pyupgrade
args: [--py38-plus, --keep-runtime-typing]
- repo: https://github.com/myint/autoflake
rev: v1.4
hooks:
- id: autoflake
args: ["--in-place", "--remove-all-unused-imports"]
- id: ruff
- repo: https://github.com/psf/black
rev: 22.3.0
rev: 24.10.0
hooks:
- id: black
- repo: https://github.com/PyCQA/flake8
rev: 4.0.1
hooks:
- id: flake8
additional_dependencies: [flake8-typing-imports>=1.9.0]
- repo: https://github.com/tlambert03/napari-plugin-checks
rev: v0.2.0
rev: v0.3.0
hooks:
- id: napari-plugin-checks
# https://mypy.readthedocs.io/en/stable/introduction.html
# https://mypy.readthedocs.io/en/stable/
# you may wish to add this as well!
# - repo: https://github.com/pre-commit/mirrors-mypy
# rev: v0.910-1
# rev: v1.9.0
# hooks:
# - id: mypy
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

Copyright (c) 2023, Loïc Sauteur
Copyright (c) 2025, Loïc Sauteur
All rights reserved.

Redistribution and use in source and binary forms, with or without
Expand Down
25 changes: 13 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# napari-annotator

[![License](https://img.shields.io/pypi/l/napari-annotator.svg?color=green)](https://github.com/loicsauteur/napari-annotator/raw/main/LICENSE)
[![License BSD-3](https://img.shields.io/pypi/l/napari-annotator.svg?color=green)](https://github.com/loicsauteur/napari-annotator/raw/main/LICENSE)
[![PyPI](https://img.shields.io/pypi/v/napari-annotator.svg?color=green)](https://pypi.org/project/napari-annotator)
[![Python Version](https://img.shields.io/pypi/pyversions/napari-annotator.svg?color=green)](https://python.org)
[![tests](https://github.com/loicsauteur/napari-annotator/workflows/tests/badge.svg)](https://github.com/loicsauteur/napari-annotator/actions)
Expand All @@ -11,14 +11,14 @@ A lightweight plugin extending label layer control.

----------------------------------

This [napari] plugin was generated with [Cookiecutter] using [@napari]'s [cookiecutter-napari-plugin] template.
This [napari] plugin was generated with [copier] using the [napari-plugin-template].

<!--
Don't miss the full getting started guide to set up your new package:
https://github.com/napari/cookiecutter-napari-plugin#getting-started
https://github.com/napari/napari-plugin-template#getting-started
and review the napari docs for plugin developers:
https://napari.org/plugins/stable/index.html
https://napari.org/stable/plugins/index.html
-->
## Description
This lightweight plugin helps you navigate your labels layer. It is intended to ease your manual annotation work.
Expand All @@ -30,24 +30,25 @@ This lightweight plugin helps you navigate your labels layer. It is intended to
- Erase all drawn pixels of a given label.
- Restore an erased label.

Version >=0.1.0 works for napari version >= 0.5.5

Version <0.1.0 should work for napari version < 0.4.19

## Usage
Start the plugin `Plugins > napari-annotator: Annotator`.
Start the plugin `Plugins > Annotator (Annotator)`.

The plugin will list available labels once a labels layer is selected and labels drawn.

Color shuffling for labels will not work, since the plugin sets the color mode of the layer to `direct`.
But you can always change the color of individual labels, using the color picker.

## Known limitations
1. Lag when drawing (probably related to [this issue](https://github.com/napari/napari/issues/2380#issue-825308887)).
2. Locating / moving to the center of a label only works on 2D/3D label layers, i.e.:
1. Locating / moving to the center of a label only works on 2D/3D label layers, i.e.:
1. single- / multi-channel 2D label layers.
2. single-channel 3D label layers (the third dimension being either Z or T).
3. Maximum 255 labels supported. Increasing number of supported label is possible, but when increasing it, colors in the canvas will mismatch the layer control and plugin entries (probably related to [this issue](https://github.com/napari/napari/issues/3174))
4. Restoring an erased labels is lost after switching between layers.
<!--#3: This mismatch will also prevent the hide button to work on those mismatched labels...-->
2. (Theoretical) maximum of 20'000 labels supported.
<!-- increasing the number is possible, but will introduce bigger lag, as each color/visibility change re-creates the colormap.-->
3. Restoring an erased labels is lost after switching between layers.



Expand Down Expand Up @@ -82,15 +83,15 @@ and a [@loicsauteur](https://github.com/loicsauteur) tag.


[napari]: https://github.com/napari/napari
[Cookiecutter]: https://github.com/audreyr/cookiecutter
[copier]: https://copier.readthedocs.io/en/stable/
[@napari]: https://github.com/napari
[MIT]: http://opensource.org/licenses/MIT
[BSD-3]: http://opensource.org/licenses/BSD-3-Clause
[GNU GPL v3.0]: http://www.gnu.org/licenses/gpl-3.0.txt
[GNU LGPL v3.0]: http://www.gnu.org/licenses/lgpl-3.0.txt
[Apache Software License 2.0]: http://www.apache.org/licenses/LICENSE-2.0
[Mozilla Public License 2.0]: https://www.mozilla.org/media/MPL/2.0/index.txt
[cookiecutter-napari-plugin]: https://github.com/napari/cookiecutter-napari-plugin
[napari-plugin-template]: https://github.com/napari/napari-plugin-template

[file an issue]: https://github.com/loicsauteur/napari-annotator/issues

Expand Down
112 changes: 109 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,14 +1,120 @@
[project]
name = "napari-annotator"
dynamic = ["version"]
description = "A lightweight plugin extending label layer control"
readme = "README.md"
license = {file = "LICENSE"}
authors = [
{name = "Loïc Sauteur"},
{email = "loic.sauteur@unibas.ch"},
]
classifiers = [
"Development Status :: 2 - Pre-Alpha",
"Framework :: napari",
"Intended Audience :: Developers",
"License :: OSI Approved :: BSD License",
"Operating System :: OS Independent",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Topic :: Scientific/Engineering :: Image Processing",
]
requires-python = ">=3.9"
dependencies = [
"numpy",
"magicgui",
"qtpy",
"scikit-image",
"napari>=0.5.5",
]

[project.optional-dependencies]
testing = [
"tox",
"pytest", # https://docs.pytest.org/en/latest/contents.html
"pytest-cov", # https://pytest-cov.readthedocs.io/en/latest/
"pytest-qt", # https://pytest-qt.readthedocs.io/en/latest/
"napari",
"pyqt5",
]

[project.entry-points."napari.manifest"]
napari-annotator = "napari_annotator:napari.yaml"

[project.urls]
"Bug Tracker" = "https://github.com/loicsauteur/napari-annotator/issues"
"Documentation" = "https://github.com/loicsauteur/napari-annotator#README.md"
"Source Code" = "https://github.com/loicsauteur/napari-annotator"
"User Support" = "https://github.com/loicsauteur/napari-annotator/issues"

[build-system]
requires = ["setuptools>=42.0.0", "wheel", "setuptools_scm"]
build-backend = "setuptools.build_meta"

[tool.setuptools]
include-package-data = true

[tool.setuptools.packages.find]
where = ["src"]

[tool.setuptools.package-data]
"*" = ["*.yaml"]


[tool.setuptools_scm]
write_to = "src/napari_annotator/_version.py"


[tool.black]
line-length = 79
target-version = ['py38', 'py39', 'py310']

[tool.ruff]
line-length = 79
lint.select = [
"E", "F", "W", #flake8
"UP", # pyupgrade
"I", # isort
"BLE", # flake8-blind-exception
"B", # flake8-bugbear
"A", # flake8-builtins
"C4", # flake8-comprehensions
"ISC", # flake8-implicit-str-concat
"G", # flake8-logging-format
"PIE", # flake8-pie
"SIM", # flake8-simplify
]
lint.ignore = [
"E501", # line too long. let black handle this
"UP006", "UP007", # type annotation. As using magicgui require runtime type annotation then we disable this.
"SIM117", # flake8-simplify - some of merged with statements are not looking great with black, reanble after drop python 3.9
]

exclude = [
".bzr",
".direnv",
".eggs",
".git",
".mypy_cache",
".pants.d",
".ruff_cache",
".svn",
".tox",
".venv",
"__pypackages__",
"_build",
"buck-out",
"build",
"dist",
"node_modules",
"venv",
"*vendored*",
"*_vendor*",
]

[tool.isort]
profile = "black"
line_length = 79
target-version = "py38"
fix = true
Loading

0 comments on commit 21bbda9

Please sign in to comment.