cookiecutter-napari-plugin icon indicating copy to clipboard operation
cookiecutter-napari-plugin copied to clipboard

npe2 cookiecutter notes

Open tlambert03 opened this issue 3 years ago • 2 comments

hey @nclack

Taking a look through the npe2 cookiecutter, instead of a PR, just want to put some tasks here that we can tackle individually:

  • [x] we shouldn't use from numpy.typing import ArrayLike in _writer for two reasons: first, it's only available in pretty new versions of numpy (I think 1.20+) and we didn't pin numpy in the users' setup.cfg. Second, it's not an accurate type., layer data can come in many types. We're trying to codify this with the LayerDataProtocol, but i wouldn't use that either. Just call it typing.Any for now.
  • [ ] writers need more docstrings with clearer expectations about what they expect, and what they should do. I know there's a link there, but it would be nice if the cookiecutter stood alone a bit more.
  • [x] #71
    def write_single_image(path: str, data: Any): ...
    # should be changed to
    def write_single_image(path: str, data: Any, meta: dict): ...
    
    and
    def write_multiple(path: str, data: List[ArrayLike], layer_types: List[str]): ...
    # should be change to
    def write_multiple(path: str, List[FullLayerData]): ...
    
    The args are passed here
  • [x] ... obviously, we should make the equivalent of the hook_specifications.py for npe2, so we have one authoritative place to look for all signatures expected by npe2. (See https://github.com/napari/npe2/pull/61)
  • [x] #70
      commands:
        - id: napari-foobar.get_reader
          python_name: napari_foobar._reader:napari_get_reader
          title: Open data with napari FooBar
        - id: napari-foobar.writer
          python_name: napari_foobar._reader:napari_get_reader
          title: Save data with napari FooBar
    
  • [x] (This one is in main like this, but just noting this so I don't forget)... in _widget.py, we should prefer viewer: 'napari.viewer.Viewer'over using the param named napari_viewer, and we should add at the top:
if TYPE_CHECKING:
    import napari.viewer
    import napari.layers
  • [ ] writer tests need improvement (possible others as well)

tlambert03 avatar Dec 13 '21 20:12 tlambert03

the equivalent of the hook_specifications.py for npe2

I like it a lot

nclack avatar Dec 13 '21 20:12 nclack

the writer test is anemic/not-present which contributes to some of these. I let that slip my mind. I'll edit the issue to add that to the list.

nclack avatar Dec 13 '21 20:12 nclack

I'll close this issue as most of the issues are probably out of date. We can make new issues (better writer docs and tests) as they surface in napari/napari-plugin-template.

jni avatar Aug 05 '24 05:08 jni