-
Notifications
You must be signed in to change notification settings - Fork 18
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
Validate plugins removed from hub before marking them stale #1301
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
5933adf
Updating processor to sanity check deletion
manasaV3 80afe8e
Adding Classifier Adapters
manasaV3 6597f45
Adding back Zulip credentials
manasaV3 b1c58d8
Fixing linting
manasaV3 122ccba
Fixing linting for napari-hub-commons
manasaV3 d9e4039
Installing libffi7
manasaV3 b9b3320
Updating ubuntu distros
manasaV3 22ef55c
Updating tests
manasaV3 5b0f4e9
Revert "Installing libffi7"
manasaV3 e515c74
Revert "Updating ubuntu distros"
manasaV3 9a5b8a0
Revert "Adding back Zulip credentials"
manasaV3 59a54a4
Fix linting
manasaV3 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import logging | ||
from functools import cache | ||
|
||
from nhcommons.utils.adapter_helpers import GithubClientHelper | ||
|
||
|
||
REPOSITORY = "https://github.com/napari/npe2api" | ||
FILE_NAME = "public/classifiers.json" | ||
LOGGER = logging.getLogger(__name__) | ||
|
||
|
||
@cache | ||
def _get_recent_query_data() -> dict: | ||
github_client_helper = GithubClientHelper(REPOSITORY) | ||
data = github_client_helper.get_file(FILE_NAME, "json") | ||
if not data: | ||
raise RuntimeError(f"Unable to fetch {FILE_NAME} from {REPOSITORY}") | ||
return data | ||
|
||
|
||
def is_plugin_active(name: str, version: str) -> bool: | ||
try: | ||
recent_query_update = _get_recent_query_data() | ||
active_versions = set(recent_query_update.get("active", {}).get(name, [])) | ||
return version in active_versions | ||
except RuntimeError: | ||
LOGGER.warning(f"Returning {name} {version} is active due to RuntimeError") | ||
return True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
from unittest.mock import Mock, call | ||
|
||
import pytest | ||
|
||
import nhcommons.utils.adapter_helpers | ||
import plugin.classifier_adapter | ||
|
||
REPOSITORY = "https://github.com/napari/npe2api" | ||
FILE_NAME = "public/classifiers.json" | ||
|
||
|
||
class TestClassifierAdapter: | ||
@pytest.fixture(autouse=True) | ||
def clear_cache(self): | ||
plugin.classifier_adapter._get_recent_query_data.cache_clear() | ||
|
||
@pytest.fixture(autouse=True) | ||
def github_client_helper(self, monkeypatch): | ||
self._github_client_helper = Mock() | ||
self._github_client_helper.get_file.side_effect = ( | ||
lambda _, __: self._classifier_json | ||
) | ||
self._github_client_helper_call = Mock( | ||
spec=nhcommons.utils.adapter_helpers.GithubClientHelper, | ||
return_value=self._github_client_helper, | ||
) | ||
monkeypatch.setattr( | ||
plugin.classifier_adapter, | ||
"GithubClientHelper", | ||
self._github_client_helper_call, | ||
) | ||
|
||
def test_handle_valid_query_data(self): | ||
self._classifier_json = {"active": {"foo": ["1.0.0", "1.0.1", "1.0.2"]}} | ||
assert True == plugin.classifier_adapter.is_plugin_active("foo", "1.0.2") | ||
assert False == plugin.classifier_adapter.is_plugin_active("foo", "0.0.9") | ||
assert False == plugin.classifier_adapter.is_plugin_active("bar", "1.0.4") | ||
self._github_client_helper_call.assert_called_once_with(REPOSITORY) | ||
self._github_client_helper.get_file.assert_called_once_with(FILE_NAME, "json") | ||
|
||
def test_handle_invalid_query_data(self): | ||
self._classifier_json = {"inactive": []} | ||
assert False == plugin.classifier_adapter.is_plugin_active("foo", "1.0.2") | ||
assert False == plugin.classifier_adapter.is_plugin_active("bar", "1.0.2") | ||
self._github_client_helper_call.assert_called_once_with(REPOSITORY) | ||
self._github_client_helper.get_file.assert_called_once_with(FILE_NAME, "json") | ||
|
||
@pytest.mark.parametrize("init_classifier_json", [None, {}]) | ||
def test_is_plugin_live_does_not_cache_error(self, init_classifier_json): | ||
# When the classifier json is not a dict with values, _get_recent_query_data() | ||
# should throw a RuntimeError | ||
self._classifier_json = init_classifier_json | ||
assert True == plugin.classifier_adapter.is_plugin_active("foo", "1.0.2") | ||
self._classifier_json = {"active": {"foo": ["1.0.0", "1.0.1", "1.0.2"]}} | ||
assert True == plugin.classifier_adapter.is_plugin_active("foo", "1.0.2") | ||
self._github_client_helper_call.assert_has_calls( | ||
[call(REPOSITORY), call(REPOSITORY)] | ||
) | ||
self._github_client_helper.get_file.assert_has_calls( | ||
[call(FILE_NAME, "json"), call(FILE_NAME, "json")] | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
might be worth logging here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe that should be captured by the log here: https://github.com/chanzuckerberg/napari-hub/pull/1301/files#diff-1c206b5606711323610de2566d4543b35e6eac13a47494df807c5f47c6d1e74dL64