Skip to content

Commit

Permalink
Add warning notification when connectivity errors occur in when openi…
Browse files Browse the repository at this point in the history
…ng the plugin manager (#6931)

Fixes napari#26

# Description

Catches connectivity errors when fetching for plugin information when
opening the plugin manager.

Although the issue lives in the plugin manager repo, the code that
fetches the code still lives in napari, hence with the PR seem to be
better resolved on this side.

# Result

## Before this PR

![napari-before](https://github.com/napari/napari/assets/3627835/6e704463-2dd3-4701-9aa5-93f2501e48fd)

## With this PR

![napari](https://github.com/napari/napari/assets/3627835/ffa3ad0a-da18-4e76-a4aa-8a007f90ce36)

The warning reads:

>There seems to be an issue with network connectivity. Remote plugins
cannot be installed, only local ones.
  • Loading branch information
goanpeca committed May 27, 2024
1 parent 3294a44 commit 2e8cdaa
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions napari_plugin_manager/plugins/npe2api.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@
TypedDict,
cast,
)
from urllib.error import HTTPError, URLError
from urllib.request import Request, urlopen

from npe2 import PackageMetadata
from typing_extensions import NotRequired

from napari.plugins.utils import normalized_name
from napari.utils.notifications import show_warning

PyPIname = str

Expand Down Expand Up @@ -65,7 +67,6 @@ class SummaryDict(_ShortSummaryDict):
conda_versions: NotRequired[list[str]]


@lru_cache
def plugin_summaries() -> list[SummaryDict]:
"""Return PackageMetadata object for all known napari plugins."""
url = 'https://npe2api.vercel.app/api/extended_summary'
Expand All @@ -83,13 +84,22 @@ def conda_map() -> dict[PyPIname, Optional[str]]:

def iter_napari_plugin_info() -> Iterator[tuple[PackageMetadata, bool, dict]]:
"""Iterator of tuples of ProjectInfo, Conda availability for all napari plugins."""
with ThreadPoolExecutor() as executor:
data = executor.submit(plugin_summaries)
_conda = executor.submit(conda_map)
try:
with ThreadPoolExecutor() as executor:
data = executor.submit(plugin_summaries)
_conda = executor.submit(conda_map)

conda = _conda.result()
data_set = data.result()
except (HTTPError, URLError):
show_warning(
'There seems to be an issue with network connectivity. '
'Remote plugins cannot be installed, only local ones.\n'
)
return

conda = _conda.result()
conda_set = {normalized_name(x) for x in conda}
for info in data.result():
for info in data_set:
info_copy = dict(info)
info_copy.pop('display_name', None)
pypi_versions = info_copy.pop('pypi_versions')
Expand Down

0 comments on commit 2e8cdaa

Please sign in to comment.