Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use full plugin_name when finding chosen reader rather than startswith #297

Merged
merged 6 commits into from
Jun 16, 2023

Conversation

DragaDoncila
Copy link
Contributor

Prior to this PR, the wrong plugin might be chosen when multiple compatible readers are available with similar names, and the user chose to use a plugin with a shorter name. As a concrete example, if a user chose explicitly to read a file with napari, but a plugin with a longer name that starts with napari was also compatible, e.g. napari-tifffile, the user's choice may have been ignored, depending on which plugin came up first in the comparison.

To avoid this, this PR changes the comparison from rdr.command.startswith to strict comparison on rdr.plugin_name. I've added a test that always passes in this branch, and only sometimes passes on main (😬) but I'm not sure if it's worth keeping it or if we are all just happy to accept the logic 🤷‍♀️

@codecov
Copy link

codecov bot commented Jun 16, 2023

Codecov Report

Merging #297 (8707304) into main (3486638) will not change coverage.
The diff coverage is 100.00%.

@@            Coverage Diff            @@
##              main      #297   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           37        37           
  Lines         2788      2788           
=========================================
  Hits          2788      2788           
Impacted Files Coverage Δ
src/npe2/io_utils.py 100.00% <100.00%> (ø)

Copy link
Member

@jni jni left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is... Pretty crazy. LOL

I can vaguely imagine the logic. Like, it's cool that git checkout works with only the first few digits of a hash... But in a world where most plugin names start with napari-, that's, um, not a good strategy! 😂

@DragaDoncila
Copy link
Contributor Author

Pretty sure the napari tests failure is unrelated... it's a napari-svg saving test

@jni
Copy link
Member

jni commented Jun 16, 2023

@DragaDoncila this seems like a genuine failure? I think?

https://github.com/napari/npe2/actions/runs/5285688739/jobs/9564414847?pr=297#step:6:241

ValueError: There is no registered plugin named 'svg'.
Names of plugins offering writers are: set()

@DragaDoncila
Copy link
Contributor Author

@jni I don't think it's possible for it to be related to this change, but I will take a closer look - I've been surprised before 😂

@jni
Copy link
Member

jni commented Jun 16, 2023

LOL Sorry, GH not updating. 😅 Um, yeah, there's been some issues with napari-svg recently but I don't know what the CI setup is/means here. I hope @tlambert03 or @Czaki might be able to comment on what the napari-tests job is supposed to catch and whether anything needs to be done here...

@jni
Copy link
Member

jni commented Jun 16, 2023

The other failure is definitely unrelated. I saw a few toots about how to drop codecov yesterday so I expect it's a widespread thing. 😂

@DragaDoncila
Copy link
Contributor Author

napari-tests runs all plugin related tests from napari's own suite to make sure changes in npe2 aren't breaking stuff on napari side. So we defs need to look into it, just don't think it's this specific change

@Czaki
Copy link
Collaborator

Czaki commented Jun 16, 2023

@jni I have described you a problem with napari-svg related test at the community meeting. The source uses the compression of strings instead of a comparison of versions.

The workaround is using a constraints file when installing napari. see #298.

We also need to add test for the latest released version of napari to avoid recent problems with npe2 0.7.0 and napari 0.4.17

jni pushed a commit that referenced this pull request Jun 16, 2023
Workaround for problem with napari-svg problem pointed in #297.

The original bug is in repository as `("0", "1", "6") > ("0", "1",
"10")` - the wrong code for version comparison.
@Czaki
Copy link
Collaborator

Czaki commented Jun 16, 2023

In the context of wrong plugin selection. In PartSeg I have 2 plugins to read tiff files. First read plain tiff, second read tiff if there is the additional file with suffix _mask.tiff. Napari randomizes which plugin contribution to use for this. Sometimes load with a mask, sometimes without.

@DragaDoncila
Copy link
Contributor Author

Sounds grim @Czaki. If you can make a reproducible example or point me to how I can run the right workflow I'll happily look into it.

@Czaki
Copy link
Collaborator

Czaki commented Jun 16, 2023

As I think it is npe2 bug, and then I open the Issue here: #299

There is a movie showing the problem in this issue.

@jni jni merged commit 31d1c90 into napari:main Jun 16, 2023
@tlambert03 tlambert03 added the bug Something isn't working label Jul 16, 2023
jni added a commit that referenced this pull request Jul 19, 2023
Following the report
[here](https://napari.zulipchat.com/#narrow/stream/212875-general/topic/reader.20plugin.20issue.20with.200.2E4.2E18)
, this PR updates the `_read` function to check if a specific reader
contribution of the form `plugin_name.reader_contribution` was passed as
`plugin_name`. This worked before #297 (though it was **not** part of
the intended public API), but will not work with `npe2>0.7.0` without
this change.

Note that this PR does not throw a specific error if the given plugin
doesn't exist - we can add a check for that but it's actually
non-trivial since the only public reader method atm is
`iter_compatible_readers`. We arguably should never be passing a
non-existent plugin this level deep so maybe that's ok.

No doubt `napari` tests will now fail, but I will go and make those
updates separately...

cc @Czaki @psobolewskiPhD

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Ashley Anderson <aganders3@gmail.com>
Co-authored-by: Nathan Clack <nclack@chanzuckerberg.com>
Co-authored-by: Nathan Clack <nclack@gmail.com>
Co-authored-by: Juan Nunez-Iglesias <jni@fastmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants