Skip to content

Commit

Permalink
Fix tests, cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
aganders3 committed Jan 14, 2025
1 parent a7919ec commit 4cdeed0
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 17 deletions.
33 changes: 19 additions & 14 deletions data-workflows/plugin/processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions napari-hub-commons/src/nhcommons/utils/pypi_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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()
}

Expand Down

0 comments on commit 4cdeed0

Please sign in to comment.