-
-
Notifications
You must be signed in to change notification settings - Fork 415
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
Bugfix: Fix regression from #5739 for passing plugin name and reader plus add test #6013
Conversation
Codecov Report
@@ Coverage Diff @@
## main #6013 +/- ##
=======================================
Coverage 91.56% 91.56%
=======================================
Files 573 573
Lines 49809 49813 +4
=======================================
+ Hits 45606 45612 +6
+ Misses 4203 4201 -2
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Keeping npe1_...
names in code make it harder to read. But everything looks ok.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As mentioned in the comment, startswith
is just not strong enough here. I'd like us to have an explicit check
napari/plugins/_npe2.py
Outdated
@@ -43,7 +43,7 @@ def read( | |||
"""Try to return data for `path`, from reader plugins using a manifest.""" | |||
|
|||
# do nothing if `plugin` is not an npe2 reader | |||
if plugin and plugin not in get_readers(): | |||
if plugin and not any(plugin.startswith(name) for name in get_readers()): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is super danger zone and is going to lead to the same issues as were fixed in napari/npe2#297. I suggest we explicitly perform a split on the '.'
here and check the full plugin name:
# do nothing if `plugin` is not an npe2 reader
if plugin:
# user might have passed 'plugin.reader_contrib' as the command
plugin_name = plugin.split('.')[0]
if plugin_name not in get_readers():
return None
I don't know if it should be our job to check down to the contribution level here - I've left that for npe2
to check - note that without napari/npe2#301, npe2 in this case may just use a different contribution... But I just don't really know if adding the check here is right...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense. I implemented your suggestion, just using partition('.')
because it seems safer in case of no delimiter and we only care about whats before the .
anyways?
Tests pass with npe2 0.7.0 and my test case with napari builtin works.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @psobolewskiPhD I've played with this all night and it seems to work like a charm!
…plus add test (#6013) # Fixes/Closes Issue with 0.4.18rc2 reported on zulip by @adamltyson https://napari.zulipchat.com/#narrow/stream/212875-general/topic/reader.20plugin.20issue.20with.200.2E4.2E18 Closes #6012 # Description In merged commit: 6847eee the method of checking whether a plugin is npe2 returns None if a reader is passed in addition to the plugin name, e.g. `my-plugin.some_reader` vs. `my-plugin` This is a regression for the case of plugins with multiple readers, as reported on zulip: https://napari.zulipchat.com/#narrow/stream/212875-general/topic/reader.20plugin.20issue.20with.200.2E4.2E18 This PR just changes the logic of the comparison so use `startswith` so just the plugin name is compared, rather than the entire string. This fixes the regression. Also, I add a test for this condition that fails on main, but passes with this fix. # References See: https://napari.zulipchat.com/#narrow/stream/212875-general/topic/reader.20plugin.20issue.20with.200.2E4.2E18
…eader plus add test (napari#6013) # Fixes/Closes Issue with 0.4.18rc2 reported on zulip by @adamltyson https://napari.zulipchat.com/#narrow/stream/212875-general/topic/reader.20plugin.20issue.20with.200.2E4.2E18 Closes napari#6012 # Description In merged commit: napari@6847eee the method of checking whether a plugin is npe2 returns None if a reader is passed in addition to the plugin name, e.g. `my-plugin.some_reader` vs. `my-plugin` This is a regression for the case of plugins with multiple readers, as reported on zulip: https://napari.zulipchat.com/#narrow/stream/212875-general/topic/reader.20plugin.20issue.20with.200.2E4.2E18 This PR just changes the logic of the comparison so use `startswith` so just the plugin name is compared, rather than the entire string. This fixes the regression. Also, I add a test for this condition that fails on main, but passes with this fix. # References See: https://napari.zulipchat.com/#narrow/stream/212875-general/topic/reader.20plugin.20issue.20with.200.2E4.2E18
This pull request has been mentioned on Image.sc Forum. There might be relevant details there: https://forum.image.sc/t/error-with-brainreg-installation/89547/3 |
Hi there, I think I encounted the same issue with:https://forum.image.sc/t/error-with-brainreg-installation/89547/3ModuleNotFoundError Traceback (most recent call last) File ~\miniconda3\envs\napari-env\lib\site-packages\npe2\manifest\utils.py:254, in import_python_name(python_name='brainreg.napari.register:brainreg_register') File ~\miniconda3\envs\napari-env\lib\importlib_init_.py:126, in import_module(name='brainreg.napari.register', package=None) File :1050, in _gcd_import(name='brainreg.napari.register', package=None, level=0) File :1027, in find_and_load(name='brainreg.napari.register', import=) File :1006, in find_and_load_unlocked(name='brainreg.napari.register', import=) File :688, in _load_unlocked(spec=ModuleSpec(name='brainreg.napari.register', load...b\site-packages\brainreg\napari\register.py')) File :883, in exec_module(self=<_frozen_importlib_external.SourceFileLoader object>, module=<module 'brainreg.napari.register' from 'C:\Use...b\site-packages\brainreg\napari\register.py'>) File :241, in call_with_frames_removed(f=, *args=(<code object at 0x000001DCCA416810, fil...te-packages\brainreg\napari\register.py", line 1>, {'BrainGlobeAtlas': <class 'brainglobe_atlasapi.bg_atlas.BrainGlobeAtlas'>, 'Dict': typing.Dict, 'Enum': <enum 'Enum'>, 'List': typing.List, 'Tuple': typing.Tuple, 'builtins': {'ArithmeticError': <class 'ArithmeticError'>, 'AssertionError': <class 'AssertionError'>, 'AttributeError': <class 'AttributeError'>, 'BaseException': <class 'BaseException'>, 'BlockingIOError': <class 'BlockingIOError'>, 'BrokenPipeError': <class 'BrokenPipeError'>, 'BufferError': <class 'BufferError'>, 'BytesWarning': <class 'BytesWarning'>, 'ChildProcessError': <class 'ChildProcessError'>, 'ConnectionAbortedError': <class 'ConnectionAbortedError'>, ...}, 'cached': r'C:\Users\muhang\miniconda3\envs\napari-env\lib\s...inreg\napari_pycache\register.cpython-310.pyc', 'doc': None, 'file': r'C:\Users\muhang\miniconda3\envs\napari-env\lib\site-packages\brainreg\napari\register.py', 'loader': <_frozen_importlib_external.SourceFileLoader object>, ...}), **kwds={}) File ~\miniconda3\envs\napari-env\lib\site-packages\brainreg\napari\register.py:13 ModuleNotFoundError: No module named 'brainglobe_napari_io' The above exception was the direct cause of the following exception: RuntimeError Traceback (most recent call last) File ~\miniconda3\envs\napari-env\lib\site-packages\napari_qt\qt_main_window.py:876, in Window.add_plugin_dock_widget(self=<napari._qt.qt_main_window.Window object>, plugin_name='brainreg', widget_name='Atlas Registration', tabify=False) File ~\miniconda3\envs\napari-env\lib\site-packages\napari\plugins_npe2.py:136, in get_widget_contribution(plugin_name='brainreg', widget_name='Atlas Registration') File ~\miniconda3\envs\napari-env\lib\site-packages\npe2\manifest\contributions_widgets.py:49, in WidgetContribution.get_callable(self=WidgetContribution(command='brainreg.Register', ...ay_name='Atlas Registration', autogenerate=False), _registry=None) File ~\miniconda3\envs\napari-env\lib\site-packages\npe2\manifest\utils.py:71, in Executable.get_callable(self=WidgetContribution(command='brainreg.Register', ...ay_name='Atlas Registration', autogenerate=False), _registry=<npe2._command_registry.CommandRegistry object>) File ~\miniconda3\envs\napari-env\lib\site-packages\npe2_command_registry.py:138, in CommandRegistry.get(self=<npe2._command_registry.CommandRegistry object>, id='brainreg.Register') File ~\miniconda3\envs\napari-env\lib\site-packages\npe2_command_registry.py:34, in CommandHandler.resolve(self=CommandHandler(id='brainreg.Register', function=...ame='brainreg.napari.register:brainreg_register')) RuntimeError: Failed to import command at 'brainreg.napari.register:brainreg_register': No module named 'brainglobe_napari_io' |
Hi @Virginia9733, could you try updating your version of napari and brainreg ( |
It works, thank you! |
Yes, it only supports 3D images. We are building a new tool to handle registration of 2D and 3D data but it's still early days. We're always happy to help with any BrainGlobe questions, but please use one of our contact channels. This is the napari issue tracker and there's likely to be many people getting unnecessary notifications! |
Fixes/Closes
Issue with 0.4.18rc2 reported on zulip by @adamltyson
https://napari.zulipchat.com/#narrow/stream/212875-general/topic/reader.20plugin.20issue.20with.200.2E4.2E18
Closes #6012
Description
In merged commit: 6847eee
the method of checking whether a plugin is npe2 returns None if a reader is passed in addition to the plugin name, e.g.
my-plugin.some_reader
vs.my-plugin
This is a regression for the case of plugins with multiple readers, as reported on zulip:
https://napari.zulipchat.com/#narrow/stream/212875-general/topic/reader.20plugin.20issue.20with.200.2E4.2E18
This PR just changes the logic of the comparison so use
startswith
so just the plugin name is compared, rather than the entire string. This fixes the regression.Also, I add a test for this condition that fails on main, but passes with this fix.
References
See: https://napari.zulipchat.com/#narrow/stream/212875-general/topic/reader.20plugin.20issue.20with.200.2E4.2E18
Type of change
How has this been tested?
Final checklist: