Skip to content

Commit

Permalink
Use some features from npe2 v0.5.0 (napari#4719)
Browse files Browse the repository at this point in the history
* bump version

* use npe2pm
  • Loading branch information
tlambert03 authored Jun 23, 2022
1 parent 4db1d8f commit b961a21
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 21 deletions.
2 changes: 1 addition & 1 deletion napari/_qt/dialogs/qt_plugin_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -814,7 +814,7 @@ def _add_to_installed(distname, enabled, npe_version=1):
continue
enabled = not pm2.is_disabled(manifest.name)
# if it's an Npe1 adaptor, call it v1
npev = 'shim' if 'npe1' in type(manifest).__name__.lower() else 2
npev = 'shim' if manifest.npe1_shim else 2
_add_to_installed(distname, enabled, npe_version=npev)

for (
Expand Down
34 changes: 15 additions & 19 deletions napari/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,25 +28,26 @@ def get_reader(path):
...
```
"""
from __future__ import annotations

try:
__import__('dotenv').load_dotenv()
except ModuleNotFoundError:
pass

import itertools
import os
from functools import partial
from itertools import chain
from multiprocessing.pool import ThreadPool
from pathlib import Path
from typing import TYPE_CHECKING
from unittest.mock import patch

import dask.threaded
import numpy as np
import pooch
import pytest
from IPython.core.history import HistoryManager
from npe2 import DynamicPlugin, PluginManager, PluginManifest

from napari.components import LayerList
from napari.layers import Image, Labels, Points, Shapes, Vectors
Expand Down Expand Up @@ -79,6 +80,10 @@ def fetch(data_name):
return path


if TYPE_CHECKING:
from npe2._pytest_plugin import TestPluginManager


def pytest_addoption(parser):
"""Add napari specific command line options.
Expand Down Expand Up @@ -466,30 +471,21 @@ def _no_error_reports():


@pytest.fixture(autouse=True)
def _mock_npe2_pm():
"""Mock plugin manager with no registered plugins."""
with patch.object(PluginManager, 'discover'):
_pm = PluginManager()
with patch('npe2.PluginManager.instance', return_value=_pm):
yield _pm
def _npe2pm(npe2pm):
"""Autouse the npe2 mock plugin manager with no registered plugins."""
return npe2pm


@pytest.fixture
def builtins(_mock_npe2_pm: PluginManager):
plugin = DynamicPlugin('napari', plugin_manager=_mock_npe2_pm)
mf = PluginManifest.from_file(Path(__file__).parent / 'builtins.yaml')
plugin.manifest = mf
with plugin:
def builtins(_npe2pm: TestPluginManager):
mf_path = str(Path(__file__).parent / 'builtins.yaml')
with _npe2pm.tmp_plugin(manifest=mf_path) as plugin:
yield plugin


@pytest.fixture
def tmp_plugin(_mock_npe2_pm: PluginManager):
# guarantee that the name is unique, even if tmp_plugin has already been used
count = itertools.count(0)
while (name := f'tmp_plugin{next(count)}') in _mock_npe2_pm._manifests:
continue
with DynamicPlugin(name, plugin_manager=_mock_npe2_pm) as plugin:
def tmp_plugin(_npe2pm: TestPluginManager):
with _npe2pm.tmp_plugin() as plugin:
yield plugin


Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ install_requires =
napari-console>=0.0.4
napari-plugin-engine>=0.1.9
napari-svg>=0.1.6
npe2>=0.4.0
npe2>=0.5.0
numpy>=1.18.5
numpydoc>=0.9.2
pandas>=1.1.0 ; python_version < '3.9'
Expand Down

0 comments on commit b961a21

Please sign in to comment.