From f3fbd3fadfbcf8d6d1b366ecb6667866c8c6837c Mon Sep 17 00:00:00 2001 From: Draga Doncila Pop Date: Thu, 15 Jun 2023 17:11:36 +1000 Subject: [PATCH 1/4] Fix reader plugin comparison to use full plugin name not just startswith --- src/npe2/io_utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/npe2/io_utils.py b/src/npe2/io_utils.py index 7c002469..a6462528 100644 --- a/src/npe2/io_utils.py +++ b/src/npe2/io_utils.py @@ -155,7 +155,7 @@ def _read( _pm = PluginManager.instance() for rdr in _pm.iter_compatible_readers(paths): - if plugin_name and not rdr.command.startswith(plugin_name): + if plugin_name and rdr.plugin_name != plugin_name: continue read_func = rdr.exec( kwargs={"path": paths, "stack": stack, "_registry": _pm.commands} From 556fbc3d6b84f572a278a03ed5849662f9d1afa4 Mon Sep 17 00:00:00 2001 From: Draga Doncila Pop Date: Fri, 16 Jun 2023 12:36:09 +1000 Subject: [PATCH 2/4] Add kind of insane test for this case --- tests/test__io_utils.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/tests/test__io_utils.py b/tests/test__io_utils.py index aa9b64a0..00f8c760 100644 --- a/tests/test__io_utils.py +++ b/tests/test__io_utils.py @@ -32,6 +32,30 @@ def test_read_with_no_plugin(): with pytest.raises(ValueError, match="No readers returned"): read(["some.nope"], stack=False) +def test_read_uses_correct_passed_plugin(tmp_path): + pm = PluginManager() + long_name = "gooby-again" + short_name = "gooby" + long_name_plugin = DynamicPlugin(long_name, plugin_manager=pm) + short_name_plugin = DynamicPlugin(short_name, plugin_manager=pm) + + path = "something.fzzy" + mock_file = tmp_path / path + mock_file.touch() + + @long_name_plugin.contribute.reader(filename_patterns=["*.fzzy"]) + def get_read(path=mock_file): + raise ValueError(f"Uhoh, {long_name} was chosen, but given plugin was {short_name}") + + @short_name_plugin.contribute.reader(filename_patterns=["*.fzzy"]) + def get_read(path=mock_file): + def read(paths): + return [(None,)] + return read + + # "gooby-again" isn't used even though given plugin starts with the same name + # if an error is thrown here, it means we selected the wrong plugin + io_utils._read(["some.fzzy"], plugin_name=short_name, stack=False, _pm=pm) def test_read_return_reader(uses_sample_plugin): data, reader = read_get_reader("some.fzzy") From 782dc1e662a7be01ccd225feed1bb9b1e6680b28 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 16 Jun 2023 02:43:56 +0000 Subject: [PATCH 3/4] style: [pre-commit.ci] auto fixes [...] --- tests/test__io_utils.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tests/test__io_utils.py b/tests/test__io_utils.py index 00f8c760..32ce733d 100644 --- a/tests/test__io_utils.py +++ b/tests/test__io_utils.py @@ -32,6 +32,7 @@ def test_read_with_no_plugin(): with pytest.raises(ValueError, match="No readers returned"): read(["some.nope"], stack=False) + def test_read_uses_correct_passed_plugin(tmp_path): pm = PluginManager() long_name = "gooby-again" @@ -45,18 +46,22 @@ def test_read_uses_correct_passed_plugin(tmp_path): @long_name_plugin.contribute.reader(filename_patterns=["*.fzzy"]) def get_read(path=mock_file): - raise ValueError(f"Uhoh, {long_name} was chosen, but given plugin was {short_name}") + raise ValueError( + f"Uhoh, {long_name} was chosen, but given plugin was {short_name}" + ) @short_name_plugin.contribute.reader(filename_patterns=["*.fzzy"]) def get_read(path=mock_file): def read(paths): return [(None,)] + return read # "gooby-again" isn't used even though given plugin starts with the same name # if an error is thrown here, it means we selected the wrong plugin io_utils._read(["some.fzzy"], plugin_name=short_name, stack=False, _pm=pm) + def test_read_return_reader(uses_sample_plugin): data, reader = read_get_reader("some.fzzy") assert data == [(None,)] From 922ab570102702927740acefa44c9b15dafbfe76 Mon Sep 17 00:00:00 2001 From: Draga Doncila Pop Date: Fri, 16 Jun 2023 12:45:56 +1000 Subject: [PATCH 4/4] Disambiguate get_read functions --- tests/test__io_utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test__io_utils.py b/tests/test__io_utils.py index 00f8c760..7c65b9c1 100644 --- a/tests/test__io_utils.py +++ b/tests/test__io_utils.py @@ -44,7 +44,7 @@ def test_read_uses_correct_passed_plugin(tmp_path): mock_file.touch() @long_name_plugin.contribute.reader(filename_patterns=["*.fzzy"]) - def get_read(path=mock_file): + def get_read_long(path=mock_file): raise ValueError(f"Uhoh, {long_name} was chosen, but given plugin was {short_name}") @short_name_plugin.contribute.reader(filename_patterns=["*.fzzy"])