# Tutorial for developing plugin with napari
Largely inspired from the [tutorial](https://napari.org/stable/plugins/first_plugin.html) on the official [napari] website
## Pre-requisites
1. Python
1. Environment manager ([conda], preferably __*not*__ Anaconda!!)
1. Some knowledge in Python
1. Some knowledge in [napari]
__Everything should be ran in a local environement to avoid breaking everything!__
## Setting-up the environment
### Creating and activating the environment
conda create -n napari-tuto -c conda-forge
conda activate napari-tuto
### Installing [napari]
conda install "napari[all]"
Once installed, you should be able to run the command `napari` from anywhere in a terminal and it should start [napari]
### Installing [cookiecutter]
conda install cookiecutter
Cookiecutter allows you to create the folders and file layout that will be the basis for your plugin.
### Setting up your first plugin layout
cookiecutter https://github.com/napari/cookiecutter-napari-plugin
It will ask few questions:
full_name [Napari Developer]: Leo
email [yourname@example.com]: leo@leo.leo
github_username_or_organization [githubuser]: leo
plugin_name [napari-foobar]: napari-first
Select github_repository_url:
1 - https://github.com/leo/napari-first
2 - provide later
Choose from 1, 2 [1]: 2
module_name [napari_first]:
display_name [FooBar Segmentation]: My First Napari Plugin
short_description [A simple plugin to use FooBar segmentation within napari]: A simple first plugin
include_reader_plugin [y]: n
include_writer_plugin [y]: n
include_sample_data_plugin [y]: n
include_widget_plugin [y]:
use_git_tags_for_versioning [n]:
install_precommit [n]:
Using the previous parameters it will create a folder `napari-first` with the following layout:
napari-first
├── .github
│ └── workflows
│ └── test_and_deploy.yml
├── .gitignore
├── .napari-hub
│ ├── DESCRIPTION.md
│ └── config.yml
├── .pre-commit-config.yaml
├── LICENSE
├── MANIFEST.in
├── README.md
├── pyproject.toml
├── setup.cfg
├── src
│ └── napari_first
│ ├── __init__.py
│ ├── _tests
│ │ ├── __init__.py
│ │ └── test_widget.py
│ ├── _widget.py
│ └── napari.yaml
└── tox.ini
### Installing your plugin
Now, to install the plugin you can run the following command from the `napari-first` folder:
pip install -e .
Note the `-e` option for the `pip install` command it allows to install the plugin "in place" meaning that if you modify the code it will be directly integrated without having to re-install it.
Here is a small description of the files we will be looking at during this introduction:
| File name | Description |
|---|---|
|`README.md` | a file containing the instruction for your plugin|
|`setup.cfg` | the file that allows the installation of your plugin and its dependencies|
|`napari.yaml` | the file that tells [napari] where to find your plugin code and how to load it|
|`__init__.py` | the file that tells how to load the code|
|`_widget.py` | the file that contains the core of your plugin.|
If we have time we will look at the following files (likely in that order):
| File name | Description |
|---|---|
| `test_and_deploy.yml` | a file containing the information for testing when pushing on GitHub
| `_tests` | a folder containing the test files
|`pyproject.toml` | a file containing some parameters for your coding preferences|
[conda]: https://docs.conda.io/en/latest/
[napari]: https://napari.org/stable/
[cookiecutter]: https://github.com/cookiecutter/cookiecutter