Skip to content

Commit

Permalink
Make sure npe2 and npe1 builtins are available in dialogs (napari#4575)
Browse files Browse the repository at this point in the history
Co-authored-by: Juan Nunez-Iglesias <[email protected]>
  • Loading branch information
DragaDoncila and jni authored May 26, 2022
1 parent a0cd4b5 commit 35ae7f2
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 10 deletions.
3 changes: 2 additions & 1 deletion docs/release/release_0_4_16.md
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,8 @@ We have thought carefully about these choices, but there are still some open que
console, so this is strictly an improvement!)
- Allow resizing left dock widgets (#4368)
- Add filename pattern to reader associations to preference dialog (#4459)
- Add preference saving from dialog for folders with extensions (#4535)
- Add preference saving from dialog for folders with extensions #4535
- Make sure npe2 and npe1 builtins are available in dialogs (#4575)
- Open reader dialog when running napari from shell (#4569)

## Deprecations
Expand Down
2 changes: 1 addition & 1 deletion napari/components/_tests/test_viewer_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -901,7 +901,7 @@ def test_open_or_get_error_preferred_fails(tmp_path):
pth = tmp_path / 'my-file.npy'

with restore_settings_on_exit():
get_settings().plugins.extension2reader = {'.npy': 'napari'}
get_settings().plugins.extension2reader = {'*.npy': 'napari'}

with pytest.raises(
ReaderPluginError, match='Tried opening with napari, but failed.'
Expand Down
9 changes: 7 additions & 2 deletions napari/plugins/_tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ def test_get_potential_readers_gives_napari(mock_npe2_pm, tmp_reader):
tmp_reader(mock_npe2_pm, 'napari', ['*.tif'])
readers = get_potential_readers(pth)
assert 'napari' in readers
assert 'builtins' not in readers
assert 'builtins' in readers
assert readers['napari'] == 'napari (npe2)'
assert readers['builtins'] == 'builtins (npe1)'


def test_get_potential_readers_finds_readers(mock_npe2_pm, tmp_reader):
Expand Down Expand Up @@ -91,9 +93,12 @@ def test_get_all_readers_gives_npe1(mock_npe2_pm):

def test_get_all_readers_gives_napari():
npe2_readers, npe1_readers = get_all_readers()
assert len(npe1_readers) == 0
assert len(npe1_readers) == 1
assert len(npe2_readers) == 1
assert 'napari' in npe2_readers
assert npe2_readers['napari'] == 'napari (npe2)'
assert 'builtins' in npe1_readers
assert npe1_readers['builtins'] == 'builtins (npe1)'


def test_get_all_readers(mock_npe2_pm, tmp_reader):
Expand Down
16 changes: 10 additions & 6 deletions napari/plugins/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,11 @@ def get_potential_readers(filename: str) -> Dict[str, str]:
] = get_reader.plugin_name
readers.update(npe1_readers)

# if npe2 is present, remove npe1 builtins
if 'napari' in readers and 'builtins' in readers:
del readers['builtins']
# if npe1 and npe2 builtins are present, disambiguate
if 'napari' in readers:
readers['napari'] = 'napari (npe2)'
if 'builtins' in readers:
readers['builtins'] = 'builtins (npe1)'

return readers

Expand All @@ -69,9 +71,11 @@ def get_all_readers() -> Tuple[Dict[str, str], Dict[str, str]]:
for get_reader in potential_readers:
npe1_readers[get_reader.plugin_name] = get_reader.plugin_name

# if npe2 is present, remove npe1 builtins
if 'napari' in npe2_readers and 'builtins' in npe1_readers:
del npe1_readers['builtins']
# if npe1 and npe2 builtins are present, disambiguate
if 'napari' in npe2_readers:
npe2_readers['napari'] = 'napari (npe2)'
if 'builtins' in npe1_readers:
npe1_readers['builtins'] = 'builtins (npe1)'

return npe2_readers, npe1_readers

Expand Down

0 comments on commit 35ae7f2

Please sign in to comment.