diff --git a/data-workflows/plugin/processor.py b/data-workflows/plugin/processor.py index 4f59e6d72..7721407e8 100644 --- a/data-workflows/plugin/processor.py +++ b/data-workflows/plugin/processor.py @@ -37,8 +37,24 @@ def _is_new_plugin(plugin_version_pair): futures.wait(update_futures, return_when="ALL_COMPLETED") + def _mark_version_stale(name, version) -> None: + logger.info(f"Updating old plugin={name} version={version}") + put_plugin_metadata( + plugin=name, + version=version, + plugin_metadata_type=PluginMetadataType.PYPI, + ) + # update for removed plugins and existing older version of plugins for name, version in dynamo_latest_plugins.items(): + if name != (normalized := pypi_adapter.normalize(name)): + logger.info( + f"Found non-normalized name, will be removed plugin={name} " + f"(normalized={normalized})" + ) + _mark_version_stale(name, version) + continue + pypi_plugin_version = pypi_latest_plugins.get(name) if pypi_plugin_version == version: continue @@ -50,22 +66,11 @@ def _is_new_plugin(plugin_version_pair): ) continue - logger.info(f"Updating old plugin={name} version={version}") - put_plugin_metadata( - plugin=name, - version=version, - plugin_metadata_type=PluginMetadataType.PYPI, - ) + _mark_version_stale(name, version) if pypi_plugin_version is None: - logger.info(f"Plugin no longer on hub: plugin={name}") - if name == pypi_adapter.pypi_name_normalize(name): - zulip.plugin_no_longer_on_hub(name) - else: - logger.info( - f"Skipping zulip removal notification plugin={name}, " - "name is not normalized, so likely a duplicate plugin." - ) + logger.info(f"Plugin={name} will be removed from hub") + zulip.plugin_no_longer_on_hub(name) def _update_for_new_plugin(name: str, version: str, old_version: Optional[str]) -> None: diff --git a/napari-hub-commons/src/nhcommons/tests/utils/test_pypi_adapter.py b/napari-hub-commons/src/nhcommons/tests/utils/test_pypi_adapter.py index ca2f5a0e3..8a873bc69 100644 --- a/napari-hub-commons/src/nhcommons/tests/utils/test_pypi_adapter.py +++ b/napari-hub-commons/src/nhcommons/tests/utils/test_pypi_adapter.py @@ -149,7 +149,10 @@ def _mocked_requests_get(self, *args, **kwargs): return MockResponse(status_code=requests.codes.not_found) def test_get_all_plugins(self): - expected = {plugin[0]: plugin[1] for plugin in plugins()} + expected = { + pypi_adapter.normalize(plugin[0]): plugin[1] + for plugin in plugins() + } assert expected == pypi_adapter.get_all_plugins() @pytest.mark.parametrize( diff --git a/napari-hub-commons/src/nhcommons/utils/pypi_adapter.py b/napari-hub-commons/src/nhcommons/utils/pypi_adapter.py index decc664f1..d5d39187d 100644 --- a/napari-hub-commons/src/nhcommons/utils/pypi_adapter.py +++ b/napari-hub-commons/src/nhcommons/utils/pypi_adapter.py @@ -17,7 +17,7 @@ logger = logging.getLogger(__name__) -def pypi_name_normalize(name: str) -> str: +def normalize(name: str) -> str: """ Normalize the plugin name to lowercase and replace special characters with hyphen. @@ -42,7 +42,7 @@ def get_all_plugins() -> Dict[str, str]: packages = get_request(_NPE2API_URL + "/plugins").json() logger.info(f"Total number of napari plugins fetched={len(packages)}") return { - pypi_name_normalize(name): version + normalize(name): version for name, version in packages.items() }