napari.plugins.PluginManifest

class napari.plugins.PluginManifest(*, name: str, display_name: str = '', schema_version: str = '0.1.0', on_activate: PythonName = None, on_deactivate: PythonName = None, contributions: npe2.manifest.contributions._contributions.ContributionPoints = None, package_metadata: npe2.manifest._package_metadata.PackageMetadata = None, npe1_shim: bool = False)[source]

Bases: npe2.manifest._bases.ImportExportModel

Methods

construct([_fields_set])

Creates a new model setting __dict__ and __fields_set__ from trusted or pre-validated data.

copy(*[, include, exclude, update, deep])

Duplicate a model, optionally choose which fields to include, exclude and change.

dict(*[, include, exclude, by_alias, ...])

Generate a dictionary representation of the model, optionally specifying which fields to include or exclude.

discover([paths])

Discover manifests in the environment.

from_distribution(name)

Return PluginManifest given a distribution (package) name.

from_file(path)

Parse model from a metadata file.

from_orm(obj)

json(*[, include, exclude, by_alias, ...])

Generate a JSON representation of the model, include and exclude arguments as per dict().

parse_file(path, *[, content_type, ...])

parse_obj(obj)

parse_raw(b, *[, content_type, encoding, ...])

schema([by_alias, ref_template])

schema_json(*[, by_alias, ref_template])

toml([pyproject])

Generate serialized toml string for this model.

update_forward_refs(**localns)

Try to update ForwardRefs on fields based on this Model, globalns and localns.

validate(value)

validate_imports()

Checks recursively that all python_name fields are actually importable.

yaml(**kwargs)

Generate serialized yaml string for this model.

Attributes

author

description

license

package_version

Details

exception ValidationError(errors: Sequence[Union[Sequence[Any], pydantic.error_wrappers.ErrorWrapper]], model: ModelOrDc)

Bases: pydantic.utils.Representation, ValueError

with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

classmethod construct(_fields_set: Optional[SetStr] = None, **values: Any) Model

Creates a new model setting __dict__ and __fields_set__ from trusted or pre-validated data. Default values are respected, but no other validation is performed. Behaves as if Config.extra = ‘allow’ was set since it adds all passed values

copy(*, include: Union[AbstractSetIntStr, MappingIntStrAny] = None, exclude: Union[AbstractSetIntStr, MappingIntStrAny] = None, update: DictStrAny = None, deep: bool = False) Model

Duplicate a model, optionally choose which fields to include, exclude and change.

Parameters
  • include – fields to include in new model

  • exclude – fields to exclude from new model, as with values this takes precedence over include

  • update – values to change/add in the new model. Note: the data is not validated before creating the new model: you should trust this data

  • deep – set to True to make a deep copy of the model

Returns

new model instance

dict(*, include: Union[AbstractSetIntStr, MappingIntStrAny] = None, exclude: Union[AbstractSetIntStr, MappingIntStrAny] = None, by_alias: bool = False, skip_defaults: bool = None, exclude_unset: bool = False, exclude_defaults: bool = False, exclude_none: bool = False) DictStrAny

Generate a dictionary representation of the model, optionally specifying which fields to include or exclude.

classmethod discover(paths: Sequence[Union[str, pathlib.Path]] = ()) Iterator[npe2.manifest.schema.DiscoverResults][source]

Discover manifests in the environment.

This function searches for installed python packages with a matching entry point group and then attempts to resolve the manifest file.

The manifest file should be specified in the plugin’s setup.cfg or setup.py file using the [entry point group][1]: “napari.manifest”. For example, this would be the section for a plugin “npe-tester” with “napari.yaml” as the manifest file:

[options.entry_points]
napari.manifest =
    npe2-tester = npe2_tester:napari.yaml

The manifest file is specified relative to the submodule root path. So for the example it will be loaded from: <path/to/npe2-tester>/napari.yaml.

[1]: https://packaging.python.org/specifications/entry-points/

Parameters

paths (Sequence[str], optional) – paths to add to sys.path while discovering.

Yields

DiscoverResults ((3 namedtuples: manifest, entrypoint, error)) – 3-tuples with either manifest or (entrypoint and error) being None.

classmethod from_distribution(name: str) npe2.manifest.schema.PluginManifest[source]

Return PluginManifest given a distribution (package) name.

Parameters

name (str) – Name of a python distribution installed in the environment. Note: this is the package name, not the top level module name, (e.g. “scikit-image”, not “skimage”).

Returns

The parsed manifest.

Return type

PluginManifest

Raises
  • ValueError – If the distribution exists, but does not provide a manifest

  • PackageNotFoundError – If there is no distribution found for name

  • ValidationError – If the manifest is not valid

classmethod from_file(path: Union[pathlib.Path, str])

Parse model from a metadata file.

Parameters

path (Path or str) – Path to file. Must have extension {‘.json’, ‘.yaml’, ‘.yml’, ‘.toml’}

Returns

The parsed model.

Return type

object

Raises
  • FileNotFoundError – If path does not exist.

  • ValueError – If the file extension is not in {‘.json’, ‘.yaml’, ‘.yml’, ‘.toml’}

json(*, include: Union[AbstractSetIntStr, MappingIntStrAny] = None, exclude: Union[AbstractSetIntStr, MappingIntStrAny] = None, by_alias: bool = False, skip_defaults: bool = None, exclude_unset: bool = False, exclude_defaults: bool = False, exclude_none: bool = False, encoder: Optional[Callable[[Any], Any]] = None, models_as_dict: bool = True, **dumps_kwargs: Any) unicode

Generate a JSON representation of the model, include and exclude arguments as per dict().

encoder is an optional function to supply as default to json.dumps(), other arguments as per json.dumps().

toml(pyproject=False, **kwargs) str

Generate serialized toml string for this model.

Parameters
  • pyproject (bool, optional) – If True, output will be in pyproject format, with all data under tool.napari, by default False.

  • **kwargs – passed to BaseModel.json()

classmethod update_forward_refs(**localns: Any) None

Try to update ForwardRefs on fields based on this Model, globalns and localns.

validate_imports() None[source]

Checks recursively that all python_name fields are actually importable.

yaml(**kwargs) str

Generate serialized yaml string for this model.

Parameters

**kwargs – passed to BaseModel.json()