Skip to content

Commit

Permalink
Remove 'is_active' check now that npe2api is source of truth
Browse files Browse the repository at this point in the history
  • Loading branch information
aganders3 committed Jan 14, 2025
1 parent 4d8efa5 commit bcbdd73
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 135 deletions.
28 changes: 0 additions & 28 deletions data-workflows/plugin/classifier_adapter.py

This file was deleted.

23 changes: 6 additions & 17 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 @@ -49,28 +48,18 @@ def _mark_version_stale(name, version) -> None:
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"Found non-normalized name, plugin={name} will be removed"
f"(normalized={normalized})"
)
_mark_version_stale(name, version)
continue

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 "
"plugin is still active in npe2api"
)
continue

_mark_version_stale(name, version)

if pypi_plugin_version is None:
logger.info(f"Plugin={name} will be removed from hub")
zulip.plugin_no_longer_on_hub(name)
if pypi_plugin_version != version:
_mark_version_stale(name, version)
if pypi_plugin_version is None:
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
61 changes: 0 additions & 61 deletions data-workflows/plugin/tests/test_classifier_adapter.py

This file was deleted.

53 changes: 24 additions & 29 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,35 @@ 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)

def test_non_normalized_plugin_name(self, verify_calls):
non_normalized_plugin_name = PLUGIN.upper()
self._dynamo_latest_plugins = {
PLUGIN: VERSION,
non_normalized_plugin_name: VERSION,
}
self._pypi_latest_plugins = {"foo": VERSION}

processor.update_plugin()

self._zulip.assert_not_called()
put_pm_calls = [
_create_put_pm_call(PMType.PYPI, name=non_normalized_plugin_name)
]
verify_calls(put_pm_calls=put_pm_calls)

@pytest.mark.parametrize(
"existing_types, put_pm_data, formatted_metadata",
Expand Down Expand Up @@ -273,8 +266,10 @@ def test_replace_old_plugin_version_with_new(
self._zulip.assert_not_called()


def _create_put_pm_call(pm_type, data=None, is_latest=False, version=VERSION) -> call:
kwargs = {"plugin": PLUGIN, "version": version, "plugin_metadata_type": pm_type}
def _create_put_pm_call(
pm_type, data=None, is_latest=False, version=VERSION, name=PLUGIN
) -> call:
kwargs = {"plugin": name, "version": version, "plugin_metadata_type": pm_type}
if is_latest:
kwargs["is_latest"] = is_latest

Expand Down

0 comments on commit bcbdd73

Please sign in to comment.