Skip to content

Commit

Permalink
add visibility field (#234)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
tlambert03 and DragaDoncila authored Aug 12, 2022
1 parent a2ab749 commit 1c8b3ee
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
14 changes: 13 additions & 1 deletion npe2/manifest/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions tests/test_docs.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import sys
from pathlib import Path

import pytest
Expand All @@ -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"))
Expand Down
11 changes: 11 additions & 0 deletions tests/test_manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

0 comments on commit 1c8b3ee

Please sign in to comment.