Skip to content

Commit

Permalink
Read visibility from manifest, not github (#1261)
Browse files Browse the repository at this point in the history
As proposed in the config.yml deprecation plan, this PR updates metadata processing to read the visibility field from the plugin manifest, rather than from config.yml.
  • Loading branch information
DragaDoncila committed Sep 28, 2023
1 parent 34b5ebd commit 9b2c9f3
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 83 deletions.
2 changes: 2 additions & 0 deletions data-workflows/plugin/manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ def _parse_manifest(manifest: Optional[dict[str, Any]]) -> dict[str, Any]:
"reader_file_extensions": [],
"writer_file_extensions": [],
"writer_save_layers": [],
"visibility": "public",
"category": {},
"category_hierarchy": {},
}
Expand All @@ -100,6 +101,7 @@ def _parse_manifest(manifest: Optional[dict[str, Any]]) -> dict[str, Any]:

result["display_name"] = manifest.get("display_name", "")
result["npe2"] = not manifest.get("npe1_shim", False)
result["visibility"] = manifest.get("visibility", "public")
raw_categories = manifest.get("categories", {})
if raw_categories:
result["category"], result["category_hierarchy"] = _map_categories(
Expand Down
44 changes: 1 addition & 43 deletions data-workflows/plugin/tests/test_aggregator.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,20 +194,6 @@ def test_aggregate_for_handling_empty_aggregate(
{"visibility": "HIDDEN", "another-field": "data"},
{"visibility": "HIDDEN", "another-field": "data"},
),
(
PLUGIN,
VERSION,
{"type": PMType.PYPI, "is_latest": "true"},
{"visibility": "DISABLED"},
{"is_latest": "true", "visibility": "DISABLED", "excluded": "DISABLED"},
),
(
PLUGIN,
VERSION,
{"type": PMType.PYPI},
{"visibility": "DISABLED", "diff-field-name": "value 2"},
{"visibility": "DISABLED", "diff-field-name": "value 2"},
),
(
BLOCKED_PLUGIN,
VERSION,
Expand Down Expand Up @@ -236,13 +222,6 @@ def test_aggregate_for_handling_empty_aggregate(
{"visibility": "HIDDEN"},
{"visibility": "BLOCKED"},
),
(
BLOCKED_PLUGIN,
VERSION,
{"type": PMType.PYPI},
{"visibility": "DISABLED"},
{"visibility": "BLOCKED"},
),
(
PLUGIN,
None,
Expand Down Expand Up @@ -296,20 +275,6 @@ def test_aggregate_for_handling_empty_aggregate(
{"visibility": "HIDDEN", "another-field": "data"},
{"visibility": "HIDDEN", "another-field": "data"},
),
(
PLUGIN,
None,
{"type": PMType.PYPI, "is_latest": "true"},
{"visibility": "DISABLED"},
{"is_latest": "true", "visibility": "DISABLED", "excluded": "DISABLED"},
),
(
PLUGIN,
None,
{"type": PMType.PYPI},
{"visibility": "DISABLED", "diff-field-name": "value 2"},
{"visibility": "DISABLED", "diff-field-name": "value 2"},
),
(
BLOCKED_PLUGIN,
None,
Expand Down Expand Up @@ -337,14 +302,7 @@ def test_aggregate_for_handling_empty_aggregate(
{"type": PMType.PYPI},
{"visibility": "HIDDEN"},
{"visibility": "BLOCKED"},
),
(
BLOCKED_PLUGIN,
None,
{"type": PMType.PYPI},
{"visibility": "DISABLED"},
{"visibility": "BLOCKED"},
),
)
],
)
def test_aggregate_for_valid_data(
Expand Down
3 changes: 3 additions & 0 deletions data-workflows/plugin/tests/test_manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ def default_result(self) -> dict[str, Any]:
"reader_file_extensions": [],
"writer_file_extensions": [],
"writer_save_layers": [],
"visibility": "public",
"category": {},
"category_hierarchy": {},
}
Expand All @@ -88,6 +89,8 @@ def default_result(self) -> dict[str, Any]:
({"error": "some error"}, {}),
({"npe1_shim": True}, {"npe2": False}),
({"npe1_shim": False}, {"npe2": True}),
({"visibility": "public"}, {"visibility": "public", "npe2": True}),
({"visibility": "hidden"}, {"visibility": "hidden", "npe2": True}),
({"display_name": "foo"}, {"display_name": "foo", "npe2": True}),
(
{"categories": ["not-mapped"]},
Expand Down
1 change: 0 additions & 1 deletion napari-hub-commons/src/nhcommons/models/plugin_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,5 @@ def __contains__(cls, item):
class PluginVisibility(Enum, metaclass=PluginVisibilityMeta):
PUBLIC = auto()
HIDDEN = auto()
DISABLED = auto()
BLOCKED = auto()
INVALID = auto()
44 changes: 10 additions & 34 deletions napari-hub-commons/src/nhcommons/tests/models/test_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,14 +135,7 @@ def seed_data(self, put_item):
"2.2",
release_date="2023-03-01",
data=plugin_data("plugin-1", "2.2"),
)
put_item(
"plugin-1",
"2.3",
visibility="DISABLED",
release_date="2023-04-01",
code_repo="https://github.com/org/Plugin1",
data=plugin_data("plugin-1", "2.3"),
is_latest=True
)
put_item(
"Plugin-2",
Expand Down Expand Up @@ -181,7 +174,7 @@ def seed_data(self, put_item):
put_item(
"plugin-4",
"1.0.0",
visibility="DISABLED",
visibility="HIDDEN",
code_repo="https://github.com/org/Plugin4",
data=plugin_data("plugin-4", "1.0.0"),
)
Expand Down Expand Up @@ -231,10 +224,9 @@ def seed_data(self, put_item):
set(),
[
(plugin_data("plugin-1", "2.2"), "public"),
(plugin_data("plugin-1", "2.3"), "disabled"),
(plugin_data("Plugin-2", "1.0.0"), "public"),
(plugin_data("plugin-3", "1.0.0"), "hidden"),
(plugin_data("plugin-4", "1.0.0"), "disabled"),
(plugin_data("plugin-4", "1.0.0"), "hidden"),
(plugin_data("plugin-5", "1.0.0"), "blocked"),
],
),
Expand All @@ -246,11 +238,10 @@ def seed_data(self, put_item):
],
),
(
{pv.HIDDEN, pv.DISABLED, pv.BLOCKED},
{pv.HIDDEN, pv.BLOCKED},
[
(plugin_data("plugin-1", "2.3"), "disabled"),
(plugin_data("plugin-3", "1.0.0"), "hidden"),
(plugin_data("plugin-4", "1.0.0"), "disabled"),
(plugin_data("plugin-4", "1.0.0"), "hidden"),
(plugin_data("plugin-5", "1.0.0"), "blocked"),
],
),
Expand All @@ -267,7 +258,7 @@ def test_get_index(self, seed_data, visibilities, expected_data):
def test_get_latest_plugins(self, seed_data):
actual = plugin.get_latest_plugins()
expected = {
"plugin-1": "2.3",
"plugin-1": "2.2",
"Plugin-2": "1.0.0",
"plugin-3": "1.0.0",
"plugin-4": "1.0.0",
Expand All @@ -279,7 +270,6 @@ def test_get_latest_plugins(self, seed_data):
def test_get_plugin_name_by_repo(self, seed_data):
expected = {
"https://custom.com/org1/foo": "Plugin-2",
"org/Plugin1": "plugin-1",
"org/Plugin3": "plugin-3",
"org/Plugin4": "plugin-4",
"org/Plugin5": "plugin-5",
Expand All @@ -292,23 +282,22 @@ def test_get_plugin_name_by_repo(self, seed_data):
# Tests for latest plugin with specific visibility is returned
("plugin-1", {pv.PUBLIC}, plugin_data("plugin-1", "2.2")),
("plugin-1", {pv.HIDDEN}, {}),
("plugin-1", {pv.DISABLED}, plugin_data("plugin-1", "2.3")),
("plugin-1", {pv.BLOCKED}, {}),
("Plugin-2", {pv.PUBLIC}, plugin_data("Plugin-2", "1.0.0")),
("plugin-3", {pv.HIDDEN}, plugin_data("plugin-3", "1.0.0")),
("plugin-4", {pv.DISABLED}, plugin_data("plugin-4", "1.0.0")),
("plugin-4", {pv.HIDDEN}, plugin_data("plugin-4", "1.0.0")),
("plugin-5", {pv.BLOCKED}, plugin_data("plugin-5", "1.0.0")),
# Tests for latest plugin with any visibility is returned
("plugin-1", set(), plugin_data("plugin-1", "2.3")),
("plugin-1", set(), plugin_data("plugin-1", "2.2")),
("Plugin-2", set(), plugin_data("Plugin-2", "1.0.0")),
("plugin-3", set(), plugin_data("plugin-3", "1.0.0")),
("plugin-4", set(), plugin_data("plugin-4", "1.0.0")),
("plugin-5", set(), plugin_data("plugin-5", "1.0.0")),
# Tests for latest plugin with matching visibility is returned
(
"plugin-1",
{pv.PUBLIC, pv.DISABLED},
plugin_data("plugin-1", "2.3"),
{pv.PUBLIC, pv.HIDDEN},
plugin_data("plugin-1", "2.2"),
),
# Tests when latest plugin does not have data attribute
("plugin-6", set(), {}),
Expand Down Expand Up @@ -337,12 +326,6 @@ def test_get_latest_plugin(self, seed_data, name, visibilities, expected):
{pv.HIDDEN},
plugin_data("plugin-3", "1.0.0"),
),
(
"plugin-4",
"1.0.0",
{pv.DISABLED},
plugin_data("plugin-4", "1.0.0"),
),
(
"plugin-5",
"1.0.0",
Expand All @@ -368,12 +351,6 @@ def test_get_latest_plugin(self, seed_data, name, visibilities, expected):
{v for v in pv if v != pv.HIDDEN},
{},
),
(
"plugin-4",
"1.0.0",
{v for v in pv if v != pv.DISABLED},
{},
),
(
"plugin-5",
"1.0.0",
Expand All @@ -396,7 +373,6 @@ def test_get_plugin_by_version(
"name, expected",
[
# Tests for plugins with different visibility
("plugin-1", "2.3"),
("Plugin-2", "1.0.0"),
("plugin-3", "1.0.0"),
("plugin-4", "1.0.0"),
Expand Down
6 changes: 1 addition & 5 deletions napari-hub-commons/src/nhcommons/utils/github_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@
import yaml

from .adapter_helpers import GithubClientHelper, CitationHelper
from ..models.plugin_utils import PluginVisibility

_URL_PATTERN = re.compile("^https://github\\.com/([^/]+)/([^/]+)")
_DEFAULT_DESCRIPTION = (
"The developer has not yet provided a napari-hub " "specific description."
)
_VISIBILITY_SET = {"public", "disabled", "hidden"}
_HUB_CONFIG_KEYS = {"labels", "visibility"}
_HUB_CONFIG_KEYS = {'labels'}


def is_valid_repo_url(url: str) -> bool:
Expand Down Expand Up @@ -69,8 +67,6 @@ def get_github_metadata(repo_url: str, branch: str = "HEAD") -> Dict:
# update github metadata author info
if authors:
github_metadata.update({"authors": authors})
if github_metadata.get("visibility") not in PluginVisibility:
github_metadata["visibility"] = PluginVisibility.PUBLIC.name.lower()

yaml_file = github_helper.get_first_valid_file(
[".napari-hub/config.yml", ".napari/config.yml"]
Expand Down

0 comments on commit 9b2c9f3

Please sign in to comment.