ome / napari-ome-zarr

A napari plugin for zarr backed OME-NGFF images
https://www.napari-hub.org/plugins/napari-ome-zarr
BSD 3-Clause "New" or "Revised" License
27 stars 21 forks source link

Add minimal napari requirement for the plugin to be discovered #55

Closed sbesson closed 2 years ago

sbesson commented 2 years ago

See https://github.com/ome/napari-ome-zarr/pull/42#issuecomment-1165932251

While this plugin does not directly consume napari APIs, the plugin engine mechanism requires a minimal version of upstream napari. This proposes to use the standard Python packaging markup to capture this minimal requirement.

Proposed tag: 0.5.1

codecov-commenter commented 2 years ago

Codecov Report

Merging #55 (6121d50) into main (4e506d6) will decrease coverage by 0.16%. The diff coverage is n/a.

@@            Coverage Diff             @@
##             main      #55      +/-   ##
==========================================
- Coverage   92.59%   92.43%   -0.17%     
==========================================
  Files           3        3              
  Lines         189      185       -4     
==========================================
- Hits          175      171       -4     
  Misses         14       14              
Impacted Files Coverage Δ
napari_ome_zarr/_tests/test_reader.py 98.78% <ø> (-0.06%) :arrow_down:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 4e506d6...6121d50. Read the comment docs.

sbesson commented 2 years ago

This is now ready for review. The Python 3.7 tests started failing with an error similar to https://github.com/napari/napari/issues/4747 and I realise that napari dropped support for Python 3.7 starting with 0.4.15. This PR also adjusts the range of supported/tested versions to match upstream.

will-moore commented 2 years ago

Not related to this PR, I just started getting this error using this plugin...

stack trace ``` $ napari --plugin napari-ome-zarr 1229801.zarr /Users/wmoore/opt/anaconda3/envs/napari-env/lib/python3.9/site-packages/napari_tools_menu/__init__.py:168: FutureWarning: Public access to Window.qt_viewer is deprecated and will be removed in v0.5.0. It is considered an "implementation detail" of the napari application, not part of the napari viewer model. If your use case requires access to qt_viewer, please open an issue to discuss. self.tools_menu = ToolsMenu(self, self.qt_viewer.viewer) Traceback (most recent call last): File "/Users/wmoore/opt/anaconda3/envs/napari-env/lib/python3.9/site-packages/napari_plugin_engine/hooks.py", line 201, in get_plugin_implementation return next( StopIteration During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/Users/wmoore/opt/anaconda3/envs/napari-env/bin/napari", line 10, in sys.exit(main()) File "/Users/wmoore/opt/anaconda3/envs/napari-env/lib/python3.9/site-packages/napari/__main__.py", line 449, in main _run() File "/Users/wmoore/opt/anaconda3/envs/napari-env/lib/python3.9/site-packages/napari/__main__.py", line 314, in _run viewer = view_path( # noqa: F841 File "/Users/wmoore/opt/anaconda3/envs/napari-env/lib/python3.9/site-packages/napari/view_layers.py", line 178, in view_path return _make_viewer_then('open', args, kwargs) File "/Users/wmoore/opt/anaconda3/envs/napari-env/lib/python3.9/site-packages/napari/view_layers.py", line 126, in _make_viewer_then method(*args, **kwargs) File "/Users/wmoore/opt/anaconda3/envs/napari-env/lib/python3.9/site-packages/napari/components/viewer_model.py", line 907, in open self._add_layers_with_plugins( File "/Users/wmoore/opt/anaconda3/envs/napari-env/lib/python3.9/site-packages/napari/components/viewer_model.py", line 952, in _add_layers_with_plugins layer_data, hookimpl = read_data_with_plugins( File "/Users/wmoore/opt/anaconda3/envs/napari-env/lib/python3.9/site-packages/napari/plugins/io.py", line 84, in read_data_with_plugins reader = hook_caller._call_plugin(plugin, path=path) File "/Users/wmoore/opt/anaconda3/envs/napari-env/lib/python3.9/site-packages/napari_plugin_engine/hooks.py", line 398, in _call_plugin implementation = self.get_plugin_implementation(plugin_name) File "/Users/wmoore/opt/anaconda3/envs/napari-env/lib/python3.9/site-packages/napari_plugin_engine/hooks.py", line 207, in get_plugin_implementation raise KeyError( KeyError: "No implementation of 'napari_get_reader' found for plugin 'napari-ome-zarr'." ```

with:

$ pip freeze | grep napari
napari @ file:///home/conda/feedstock_root/build_artifacts/napari_1644109119195/work
napari-brightness-contrast==0.1.7
napari-console @ file:///home/conda/feedstock_root/build_artifacts/napari-console_1644771676323/work
-e git+ssh://git@github.com/ome/napari-ome-zarr.git@7184d7bd09f66fe8ffe0d015dfbf2b7dc7168e4c#egg=napari_ome_zarr
napari-plugin-engine @ file:///home/conda/feedstock_root/build_artifacts/napari-plugin-engine_1637358573066/work
napari-svg @ file:///home/conda/feedstock_root/build_artifacts/napari-svg_1620035609639/work
napari-tools-menu==0.1.11

From the napari UI I get version napari: 0.4.14

I pip uninstalled napari-ome-zarr, checked out this branch and then pip install -e ..

This actually fixed the problem! Now I have:

$ pip freeze | grep napari
napari @ file:///home/conda/feedstock_root/build_artifacts/napari_1644109119195/work
napari-brightness-contrast==0.1.7
napari-console @ file:///home/conda/feedstock_root/build_artifacts/napari-console_1644771676323/work
-e git+ssh://git@github.com/ome/napari-ome-zarr.git@d838bdd7c493b47037da22de73482e2dde151a30#egg=napari_ome_zarr
napari-plugin-engine @ file:///home/conda/feedstock_root/build_artifacts/napari-plugin-engine_1637358573066/work
napari-svg @ file:///home/conda/feedstock_root/build_artifacts/napari-svg_1620035609639/work
napari-tools-menu==0.1.11

Not sure I see any changes here that explain why this works now, but 🤷 .

Changes look good and build is green: 👍

will-moore commented 2 years ago

Strange that I don't see napari-ome-zarr listed under plugins, when I have just opened napari with:

$ napari --plugin napari-ome-zarr 1229801.zarr

Screenshot 2022-06-28 at 10 45 57

will-moore commented 2 years ago

Hmmm - when I try opening a Plate I get...

$ napari --plugin napari-ome-zarr https://uk1s3.embassy.ebi.ac.uk/idr/zarr/v0.3/idr0094A/7751.zarr/
/Users/wmoore/opt/anaconda3/envs/napari-env/lib/python3.9/site-packages/napari_tools_menu/__init__.py:168: FutureWarning: Public access to Window.qt_viewer is deprecated and will be removed in
v0.5.0. It is considered an "implementation detail" of the napari
application, not part of the napari viewer model. If your use case
requires access to qt_viewer, please open an issue to discuss.
  self.tools_menu = ToolsMenu(self, self.qt_viewer.viewer)
Traceback (most recent call last):
  File "/Users/wmoore/opt/anaconda3/envs/napari-env/bin/napari", line 10, in <module>
    sys.exit(main())
  File "/Users/wmoore/opt/anaconda3/envs/napari-env/lib/python3.9/site-packages/napari/__main__.py", line 449, in main
    _run()
  File "/Users/wmoore/opt/anaconda3/envs/napari-env/lib/python3.9/site-packages/napari/__main__.py", line 314, in _run
    viewer = view_path(  # noqa: F841
  File "/Users/wmoore/opt/anaconda3/envs/napari-env/lib/python3.9/site-packages/napari/view_layers.py", line 178, in view_path
    return _make_viewer_then('open', args, kwargs)
  File "/Users/wmoore/opt/anaconda3/envs/napari-env/lib/python3.9/site-packages/napari/view_layers.py", line 126, in _make_viewer_then
    method(*args, **kwargs)
  File "/Users/wmoore/opt/anaconda3/envs/napari-env/lib/python3.9/site-packages/napari/components/viewer_model.py", line 907, in open
    self._add_layers_with_plugins(
  File "/Users/wmoore/opt/anaconda3/envs/napari-env/lib/python3.9/site-packages/napari/components/viewer_model.py", line 952, in _add_layers_with_plugins
    layer_data, hookimpl = read_data_with_plugins(
  File "/Users/wmoore/opt/anaconda3/envs/napari-env/lib/python3.9/site-packages/napari/plugins/io.py", line 76, in read_data_with_plugins
    raise ValueError(
ValueError: There is no registered plugin named 'napari-ome-zarr'.
Names of plugins offering readers are: {'builtins', 'ome-types'}
will-moore commented 2 years ago

I do see napari-ome-zarr listed under Plugings > Install/Uninstall Plugings... Screenshot 2022-06-28 at 11 12 27

sbesson commented 2 years ago

Thanks @will-moore, you're right and this matches what I had found in https://github.com/ome/napari-ome-zarr/pull/42#issuecomment-1134551267. Specifically testing with the latest napari release, napari --plugin-info does not recognize this plugin

(napari) sbesson@Sebastiens-MacBook-Pro ~ % napari --plugin-info      
PluginManager for "napari"
(12 hook specs and 3 plugins)
---------------------------------------------
builtins v0.4.16                                 6 hooks
  - napari_get_reader            
  - napari_get_writer            
  - napari_write_image           
  - napari_write_labels          
  - napari_write_points          
  - napari_write_shapes          

console v0.0.4                                   0 hooks

scikit-image v0.4.16                             0 hooks
sbesson commented 2 years ago
(napari) sbesson@Sebastiens-MacBook-Pro napari-ome-zarr % npe2 validate napari-ome-zarr
✔ Manifest for 'napari-ome-zarr' valid!
(napari) sbesson@Sebastiens-MacBook-Pro napari-ome-zarr % npe2 parse napari-ome-zarr
name: napari-ome-zarr
schema_version: 0.1.0
contributions:
  commands:
  - id: napari-ome-zarr.get_reader
    title: Get Reader
    python_name: napari_ome_zarr._reader:napari_get_reader
  readers:
  - command: napari-ome-zarr.get_reader
    filename_patterns:
    - '*.zarr'
    accepts_directories: true

so I don't see an immediate issue with the manifest (upgraded in #42) itself.

will-moore commented 2 years ago

@sbesson Any idea what version of napari or napari-ome-zarr I could use to get working? I was hoping to try and test https://github.com/ome/ome-zarr-py/pull/209

will-moore commented 2 years ago

Ah, it seems that updating napari to latest fixed this issue for me... Plugin now listed: Screenshot 2022-06-28 at 13 12 16

will-moore commented 2 years ago

I can load plates now, but still not Wells (either with main branch or with https://github.com/ome/ome-zarr-py/pull/209). Error gives nothing away (and denies that napari-ome-zarr is installed):

$ napari --plugin napari-ome-zarr https://uk1s3.embassy.ebi.ac.uk/idr/zarr/v0.3/idr0094A/7751.zarr/A/1/ -vvv
...
Traceback (most recent call last):
  File "/Users/wmoore/opt/anaconda3/envs/napari-env/bin/napari", line 8, in <module>
    sys.exit(main())
  File "/Users/wmoore/opt/anaconda3/envs/napari-env/lib/python3.9/site-packages/napari/__main__.py", line 446, in main
    _run()
  File "/Users/wmoore/opt/anaconda3/envs/napari-env/lib/python3.9/site-packages/napari/__main__.py", line 311, in _run
    viewer._window._qt_viewer._qt_open(
  File "/Users/wmoore/opt/anaconda3/envs/napari-env/lib/python3.9/site-packages/napari/_qt/qt_viewer.py", line 754, in _qt_open
    self.viewer.open(
  File "/Users/wmoore/opt/anaconda3/envs/napari-env/lib/python3.9/site-packages/napari/components/viewer_model.py", line 931, in open
    self._add_layers_with_plugins(
  File "/Users/wmoore/opt/anaconda3/envs/napari-env/lib/python3.9/site-packages/napari/components/viewer_model.py", line 1134, in _add_layers_with_plugins
    layer_data, hookimpl = read_data_with_plugins(
  File "/Users/wmoore/opt/anaconda3/envs/napari-env/lib/python3.9/site-packages/napari/plugins/io.py", line 86, in read_data_with_plugins
    raise ValueError(
ValueError: There is no registered plugin named 'napari-ome-zarr'.
Names of plugins offering readers are: {'builtins', 'ome-types'}
sbesson commented 2 years ago

Tested a few napari versions (0.4.10, 0.4.13, 0.4.16) installed via a local miniconda environment using the conda-forge channel (OS X 12.3, arm64) with Python 3.10 and either the released version of napari-ome-zarr or this PR e.g.

name: napari
channels:
  - conda-forge
  - defaults
dependencies:
  - napari
  - pip
  - pip:
    - napari-ome-zarr

I never get the plugin to be recognized. Recent versions of napari simply do not list it

(napari) sbesson@Sebastiens-MacBook-Pro napari-ome-zarr % napari --version
napari version 0.4.16
(napari) sbesson@Sebastiens-MacBook-Pro napari-ome-zarr % napari --plugin-info
PluginManager for "napari"
(12 hook specs and 3 plugins)
---------------------------------------------
builtins v0.4.16                                 6 hooks
  - napari_get_reader            
  - napari_get_writer            
  - napari_write_image           
  - napari_write_labels          
  - napari_write_points          
  - napari_write_shapes          

console v0.0.4                                   0 hooks

scikit-image v0.4.16                             0 hooks

and older versions list is in Blocked plugins

(napari) sbesson@Sebastiens-MacBook-Pro ~ % napari --plugin-info 
PluginManager for "napari"
(12 hook specs and 4 plugins)
---------------------------------------------
builtins v0.4.13                                 6 hooks
  - napari_get_reader            
  - napari_get_writer            
  - napari_write_image           
  - napari_write_labels          
  - napari_write_points          
  - napari_write_shapes          

console v0.0.4                                   0 hooks

scikit-image v0.4.13                             0 hooks

svg v0.1.6                                       6 hooks
  - napari_get_writer            
  - napari_write_image           
  - napari_write_labels          
  - napari_write_points          
  - napari_write_shapes          
  - napari_write_vectors         

Blocked Plugins:
----------------
napari-ome-zarr
napari
napari-svg

My attempts at validating the plugin after the upgrade to the new plugin engine do not reveal any immediate issues

(napari) sbesson@Sebastiens-MacBook-Pro napari-ome-zarr % npe2 validate napari-ome-zarr
✔ Manifest for 'napari OME-NGFF' valid!
(napari) sbesson@Sebastiens-MacBook-Pro napari-ome-zarr % npe2 parse napari-ome-zarr
name: napari-ome-zarr
display_name: napari OME-NGFF
schema_version: 0.1.0
contributions:
  commands:
  - id: napari-ome-zarr.get_reader
    title: Get Reader
    python_name: napari_ome_zarr._reader:napari_get_reader
  readers:
  - command: napari-ome-zarr.get_reader
    filename_patterns:
    - '*.zarr'
    accepts_directories: true

@jni @DragaDoncila (and other napari developers): any suggestion on how to increase the logging verbosity and understand what causes this regression? or any obvious candidate for the root of this issue?

DragaDoncila commented 2 years ago

@sbesson I am looking into this now - I will note that on latest napari for me, pip install napari-ome-zarr recognizes the plugin just fine - though it did not read the demo data (as noted in #56)

DragaDoncila commented 2 years ago

Ok so @sbesson I've tracked down a few things:

image

name: napari-ome-zarr
schema_version: 0.1.0
contributions:
  commands:
    - id: napari-ome-zarr.get_reader
      title: Get Reader
      python_name: napari_ome_zarr._reader:napari_get_reader
  readers:
    - command: napari-ome-zarr.get_reader
      filename_patterns:
        - "*.zarr"
        - "https://*.zarr/" 
      accepts_directories: true

I hope this helps, but please don't hesitate to ping me if there's any further issues!

sbesson commented 2 years ago

Many thanks for detailed trackdown @DragaDoncila. Somehow I had missed the failing command were using trailing slash.

@will-moore I have pushed an extra commit to support *.zarr/ as it's not uncommon. Using latest napari and this branch of napari-ome-zarr, I'll leave you to test this works, then we can release these as a patch release and unnlock the ongoing contributions on wells and plate labels

sbesson commented 2 years ago

6121d50 should drop Python 3.7. On minor vs patch no strong opinion either way but my understanding is that the migration to npe2 effectively mandated a recent version of napari i.e. new versions of the plugin should not be compatible with older versions ?

joshmoore commented 2 years ago

Ah, so the original 0.5 bump essentially had this requirement it just wasn't documented. Check.

sbesson commented 2 years ago

Ah, so the original 0.5 bump essentially had this requirement it just wasn't documented. Check.

Just confirmed my statement was correct with a test environment using napari 0.4.12 with napari-ome-zarr 0.5.0

(base) sbesson@Sebastiens-MacBook-Pro ~ % cat napari.yml 
name: napari
channels:
  - conda-forge
  - defaults
dependencies:
  - napari==0.4.12
  - pip
  - pip:
    - napari-ome-zarr==0.5.0
(base) sbesson@Sebastiens-MacBook-Pro ~ % conda env create -f napari.yml 
Collecting package metadata (repodata.json): done
...
Successfully installed aiobotocore-2.3.4 aiohttp-3.8.1 aioitertools-0.10.0 aiosignal-1.2.0 async-timeout-4.0.2 botocore-1.24.21 frozenlist-1.3.0 jmespath-1.0.1 multidict-6.0.2 napari-ome-zarr-0.5.0 ome-zarr-0.5.0 s3fs-2022.5.0 yarl-1.7.2

done
#
# To activate this environment, use
#
#     $ conda activate napari
#
# To deactivate an active environment, use
#
#     $ conda deactivate

(base) sbesson@Sebastiens-MacBook-Pro ~ % napari https://uk1s3.embassy.ebi.ac.uk/idr/zarr/v0.3/9836842.zarr                              
zsh: command not found: napari
(base) sbesson@Sebastiens-MacBook-Pro ~ % conda activate napari
(napari) sbesson@Sebastiens-MacBook-Pro ~ % napari --version
/Users/sbesson/miniconda3/envs/napari/lib/python3.10/site-packages/napari/__main__.py:423: UserWarning: pythonw executable not found.
To unfreeze the menubar on macOS, click away from napari to another app, then reactivate napari. To avoid this problem, please install python.app in conda using:
conda install -c conda-forge python.app
  warnings.warn(msg)
napari version 0.4.12
(napari) sbesson@Sebastiens-MacBook-Pro ~ % napari https://uk1s3.embassy.ebi.ac.uk/idr/zarr/v0.3/9836842.zarr
/Users/sbesson/miniconda3/envs/napari/lib/python3.10/site-packages/napari/__main__.py:423: UserWarning: pythonw executable not found.
To unfreeze the menubar on macOS, click away from napari to another app, then reactivate napari. To avoid this problem, please install python.app in conda using:
conda install -c conda-forge python.app
  warnings.warn(msg)
13:00:23 ERROR PluginError: Error in plugin 'builtins', hook 'napari_get_reader'
  Cause was: ValueError('Not a zarr dataset or group: https://uk1s3.embassy.ebi.ac.uk/idr/zarr/v0.3/9836842.zarr')
    in file: /Users/sbesson/miniconda3/envs/napari/lib/python3.10/site-packages/napari/utils/io.py
    at line: 327
     author: napari team
      email: napari-steering-council@googlegroups.com
    package: napari
        url: https://napari.org
    version: 0.4.12

Traceback (most recent call last):
  File "/Users/sbesson/miniconda3/envs/napari/bin/napari", line 10, in <module>
    sys.exit(main())
  File "/Users/sbesson/miniconda3/envs/napari/lib/python3.10/site-packages/napari/__main__.py", line 431, in main
    _run()
  File "/Users/sbesson/miniconda3/envs/napari/lib/python3.10/site-packages/napari/__main__.py", line 308, in _run
    viewer = view_path(  # noqa: F841
  File "/Users/sbesson/miniconda3/envs/napari/lib/python3.10/site-packages/napari/view_layers.py", line 167, in view_path
    return _make_viewer_then('open', args, kwargs)
  File "/Users/sbesson/miniconda3/envs/napari/lib/python3.10/site-packages/napari/view_layers.py", line 117, in _make_viewer_then
    method(*args, **kwargs)
  File "/Users/sbesson/miniconda3/envs/napari/lib/python3.10/site-packages/napari/components/viewer_model.py", line 885, in open
    self._add_layers_with_plugins(
  File "/Users/sbesson/miniconda3/envs/napari/lib/python3.10/site-packages/napari/components/viewer_model.py", line 930, in _add_layers_with_plugins
    layer_data, hookimpl = read_data_with_plugins(
  File "/Users/sbesson/miniconda3/envs/napari/lib/python3.10/site-packages/napari/plugins/io.py", line 164, in read_data_with_plugins
    raise ValueError(message)
ValueError: No plugin found capable of reading 'https://uk1s3.embassy.ebi.ac.uk/idr/zarr/v0.3/9836842.zarr'.
zsh: bus error  napari https://uk1s3.embassy.ebi.ac.uk/idr/zarr/v0.3/9836842.zarr
(napari) sbesson@Sebastiens-MacBook-Pro ~ % napari --plugin napari-ome-zarr   https://uk1s3.embassy.ebi.ac.uk/idr/zarr/v0.3/9836842.zarr 
/Users/sbesson/miniconda3/envs/napari/lib/python3.10/site-packages/napari/__main__.py:423: UserWarning: pythonw executable not found.
To unfreeze the menubar on macOS, click away from napari to another app, then reactivate napari. To avoid this problem, please install python.app in conda using:
conda install -c conda-forge python.app
  warnings.warn(msg)
Traceback (most recent call last):
  File "/Users/sbesson/miniconda3/envs/napari/bin/napari", line 10, in <module>
    sys.exit(main())
  File "/Users/sbesson/miniconda3/envs/napari/lib/python3.10/site-packages/napari/__main__.py", line 431, in main
    _run()
  File "/Users/sbesson/miniconda3/envs/napari/lib/python3.10/site-packages/napari/__main__.py", line 308, in _run
    viewer = view_path(  # noqa: F841
  File "/Users/sbesson/miniconda3/envs/napari/lib/python3.10/site-packages/napari/view_layers.py", line 167, in view_path
    return _make_viewer_then('open', args, kwargs)
  File "/Users/sbesson/miniconda3/envs/napari/lib/python3.10/site-packages/napari/view_layers.py", line 117, in _make_viewer_then
    method(*args, **kwargs)
  File "/Users/sbesson/miniconda3/envs/napari/lib/python3.10/site-packages/napari/components/viewer_model.py", line 885, in open
    self._add_layers_with_plugins(
  File "/Users/sbesson/miniconda3/envs/napari/lib/python3.10/site-packages/napari/components/viewer_model.py", line 930, in _add_layers_with_plugins
    layer_data, hookimpl = read_data_with_plugins(
  File "/Users/sbesson/miniconda3/envs/napari/lib/python3.10/site-packages/napari/plugins/io.py", line 94, in read_data_with_plugins
    raise ValueError(
ValueError: There is no registered plugin named 'napari-ome-zarr'.
Names of plugins offering readers are: {'builtins'}
(napari) sbesson@Sebastiens-MacBook-Pro ~ % 
will-moore commented 2 years ago

So, this means that for HCS Wells, e.g. https://uk1s3.embassy.ebi.ac.uk/idr/zarr/v0.1/plates/7825.zarr/A/1/ we can't open them via napari-ome-zarr plugin any more?

E.g. as in https://github.com/ome/ome-zarr-py/pull/209

DragaDoncila commented 2 years ago

If you want to support opening subgroups, you could always do *.zarr* - so basically give me anything that's got .zarr in there somewhere