Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove redundant check for "active" plugins on npe2api #1335

Merged
merged 6 commits into from
Jan 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 0 additions & 28 deletions data-workflows/plugin/classifier_adapter.py

This file was deleted.

8 changes: 1 addition & 7 deletions data-workflows/plugin/processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from concurrent import futures
from typing import Optional

from plugin.classifier_adapter import is_plugin_active
from plugin.lambda_adapter import LambdaAdapter
from nhcommons.models.plugin_utils import PluginMetadataType
from nhcommons.utils import pypi_adapter
Expand Down Expand Up @@ -42,19 +41,14 @@ def _is_new_plugin(plugin_version_pair):
pypi_plugin_version = pypi_latest_plugins.get(name)
if pypi_plugin_version == version:
continue
if pypi_plugin_version is None and is_plugin_active(name, version):
logger.info(
f"Skipping marking plugin={name} version={version} stale as the "
f"plugin is still active in npe2api"
)
continue
Comment on lines -45 to -50
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the main feature of this PR. This should result in removal of the duplicate plugins we were seeing on prod.


logger.info(f"Updating old plugin={name} version={version}")
put_plugin_metadata(
plugin=name,
version=version,
plugin_metadata_type=PluginMetadataType.PYPI,
)

if pypi_plugin_version is None:
zulip.plugin_no_longer_on_hub(name)

Expand Down
61 changes: 0 additions & 61 deletions data-workflows/plugin/tests/test_classifier_adapter.py

This file was deleted.

31 changes: 4 additions & 27 deletions data-workflows/plugin/tests/test_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import pytest

import plugin.lambda_adapter
import plugin.classifier_adapter
import plugin.metadata
from nhcommons.models.plugin_utils import PluginMetadataType as PMType

Expand Down Expand Up @@ -69,15 +68,6 @@ def mock_lambda_adapter(self, monkeypatch) -> Mock:
monkeypatch.setattr(processor, "LambdaAdapter", mock)
return mock

@pytest.fixture
def mock_classifier_adapter(self, monkeypatch) -> Mock:
mock = Mock(
side_effect=lambda _, __: self._is_plugin_live,
spec=plugin.classifier_adapter,
)
monkeypatch.setattr(processor, "is_plugin_active", mock)
return mock

@pytest.fixture
def mock_zulip(self, monkeypatch) -> Mock:
mock = Mock(spec=zulip)
Expand All @@ -93,7 +83,6 @@ def setup(
mock_get_existing_types,
mock_get_formatted_metadata,
mock_lambda_adapter,
mock_classifier_adapter,
mock_zulip,
) -> None:
self._get_latest_plugins = mock_get_latest_plugins
Expand All @@ -102,7 +91,6 @@ def setup(
self._get_existing_types = mock_get_existing_types
self._get_formatted_metadata = mock_get_formatted_metadata
self._lambda_adapter = mock_lambda_adapter
self._classifier_adapter = mock_classifier_adapter
self._zulip = mock_zulip

@pytest.fixture
Expand All @@ -115,7 +103,6 @@ def _verify_calls(
get_formatted_metadata_called: bool = False,
lambda_invoked: bool = False,
put_pm_calls: list = None,
classifier_adapter_not_called: bool = True,
) -> None:
verify_call(True, self._get_latest_plugins, empty_call_list)
verify_call(True, self._get_all_plugins, empty_call_list)
Expand All @@ -138,8 +125,6 @@ def _verify_calls(
default_call_list
== self._lambda_adapter.return_value.invoke.call_args_list
)
if classifier_adapter_not_called:
self._classifier_adapter.assert_not_called()

return _verify_calls

Expand All @@ -153,27 +138,19 @@ def test_all_latest_plugin_in_dynamo(self, verify_calls):
verify_calls()
self._zulip.assert_not_called()

@pytest.mark.parametrize("is_plugin_live", [False, True])
def test_stale_plugin_in_dynamo(
self,
is_plugin_live,
verify_calls,
):
self._dynamo_latest_plugins = {PLUGIN: VERSION, "bar": "2.4.6"}
self._pypi_latest_plugins = {"bar": "2.4.6"}
self._is_plugin_live = is_plugin_live

processor.update_plugin()

if is_plugin_live:
assert len(self._zulip.method_calls) == 0
put_pm_calls = []
else:
assert len(self._zulip.method_calls) == 1
self._zulip.plugin_no_longer_on_hub.assert_called_once_with(PLUGIN)
put_pm_calls = [_create_put_pm_call(PMType.PYPI)]
verify_calls(put_pm_calls=put_pm_calls, classifier_adapter_not_called=False)
self._classifier_adapter.assert_called_once_with(PLUGIN, VERSION)
assert len(self._zulip.method_calls) == 1
self._zulip.plugin_no_longer_on_hub.assert_called_once_with(PLUGIN)
put_pm_calls = [_create_put_pm_call(PMType.PYPI)]
verify_calls(put_pm_calls=put_pm_calls)

@pytest.mark.parametrize(
"existing_types, put_pm_data, formatted_metadata",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,9 @@ def setup_method(self, monkeypatch):

def _mocked_requests_get(self, *args, **kwargs):
if args[0] == "https://api.napari.org/api/plugins":
return MockResponse(content=json.dumps({name: version for name, version in plugins()}))
return MockResponse(
content=json.dumps({name: version for name, version in plugins()})
)
elif args[0] == "https://pypi.org/pypi/napari-demo/json":
return MockResponse(content=valid_pypi_data())
elif args[0] == "https://pypi.org/pypi/default-demo/json":
Expand Down