From 1c8b3eed5e8b5d43dd738df1589b503f26033d27 Mon Sep 17 00:00:00 2001 From: Talley Lambert Date: Fri, 12 Aug 2022 14:46:23 -0700 Subject: [PATCH] add visibility field (#234) * add visibility field * add to path * Update npe2/manifest/schema.py Co-authored-by: Draga Doncila Pop <17995243+DragaDoncila@users.noreply.github.com> Co-authored-by: Draga Doncila Pop <17995243+DragaDoncila@users.noreply.github.com> --- npe2/manifest/schema.py | 14 +++++++++++++- tests/test_docs.py | 2 ++ tests/test_manifest.py | 11 +++++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/npe2/manifest/schema.py b/npe2/manifest/schema.py index 81dd139d..1e29fa5a 100644 --- a/npe2/manifest/schema.py +++ b/npe2/manifest/schema.py @@ -5,7 +5,7 @@ from importlib import metadata, util from logging import getLogger from pathlib import Path -from typing import Iterator, List, NamedTuple, Optional, Sequence, Union +from typing import Iterator, List, Literal, NamedTuple, Optional, Sequence, Union from pydantic import Extra, Field, ValidationError, root_validator, validator from pydantic.error_wrappers import ErrorWrapper @@ -66,6 +66,14 @@ class Config: _validators.display_name ) + visibility: Literal["public", "hidden"] = Field( + "public", + description="Whether this plugin should be searchable and visible in " + "the built-in plugin installer and the napari hub. By default (`'public'`) " + "all plugins are visible. To prevent your plugin from appearing in search " + "results, change this to `'hidden'`.", + ) + # Plugins rely on certain guarantees to interoperate propertly with the # plugin engine. These include the manifest specification, conventions # around python packaging, command api's, etc. Together these form a @@ -160,6 +168,10 @@ def description(self) -> Optional[str]: def author(self) -> Optional[str]: return self.package_metadata.author if self.package_metadata else None + @property + def is_visible(self) -> bool: + return self.visibility == "public" + @validator("contributions", pre=True) def _coerce_none_contributions(cls, value): return [] if value is None else value diff --git a/tests/test_docs.py b/tests/test_docs.py index 18f939fa..d1275a81 100644 --- a/tests/test_docs.py +++ b/tests/test_docs.py @@ -1,3 +1,4 @@ +import sys from pathlib import Path import pytest @@ -14,6 +15,7 @@ def test_example_manifest(): @pytest.mark.github_main_only def test_render_docs(tmp_path, monkeypatch): + sys.path.append(str(DOCS_DIR.parent)) from _docs.render import main assert not list(tmp_path.glob("*.md")) diff --git a/tests/test_manifest.py b/tests/test_manifest.py index c4f4326b..46142918 100644 --- a/tests/test_manifest.py +++ b/tests/test_manifest.py @@ -167,3 +167,14 @@ def test_dotted_name_with_command(): "commands": [{"id": "plugin.plugin-sample.command", "title": "Sample"}] }, ) + + +def test_visibility(): + mf = PluginManifest(name="myplugin") + assert mf.is_visible + + mf = PluginManifest(name="myplugin", visibility="hidden") + assert not mf.is_visible + + with pytest.raises(ValidationError): + mf = PluginManifest(name="myplugin", visibility="other")