How to make a new plugin package

Package folder architecture

Minimal files for packaging are


  • pyproject.toml

  • src/plugin_name : with a subfolder for algorithm, form, IO, …

  • in each subfolder

│   pyproject.toml
│   │
│   │   env.yaml
│   │   meta.yaml
        │   │
        │   │
        │   │
        │   │   ...
        │   │
        │   │
        │   │
        │   │

Go to package directory on and choose one package to get inspiration from. & pyproject.toml: python packaging

To write the you can follow this minimal template:

#!/usr/bin/env python
#-*- coding: utf-8 -*-

from setuptools import setup, find_packages

short_descr = "package description"
readme = open("")

# find packages
pkgs = find_packages('src')

setup_kwds = {
    name: 'plugin_name',
    version: "X.X.X",
    description: short_descr,
    long_description: readme,
    author: "Author",
    author_email: "",
    url: '',
    license: 'LGPL',
    zip_safe: False,

    packages: pkgs,

    package_dir: {'': 'src'},
    package_data: {
        "": [

    entry_points: {
        'data_plugin_group': [
            'form_plugin1 = plugin_name.form.form_plugin1',
        'io_plugin_group': [
            'io_plugin1 =',
        'algo_plugin_group': [
            'algorithm_plugin1 = plugin_name.algorithm.algorithm_plugin1',
            'algorithm_plugin2 = plugin_name.algorithm.algorithm_plugin2',
    setup_requires: [],
    install_requires: [],
    tests_require: [],
    keywords: '',

    test_suite: 'nose.collector'


This python file includes the following functions from setuptools

  • setup : create the Python Egg for the package.

  • find_packages : find modules from source directory, given as arg.

Create a setup keywords dictionary: in this dictionary you precise plugin’s name, version, licence. The requirement keywords are all left empty as we consider that dependencies are managed through the conda environment.

Advertising your plugins in the global namespace: entry points

Before your plugins can be used by gnomon they need to be advertised so gnomon can dynamically discover them. To achieve that we use a feature called entry points With entry points one can register a console command (console-script) which would run a specific function in the library or advertise modules or objects. What interest us is the second use case.

The format for declaring entry points is as follows:

entry_points = {
    'group_name': [
        # advertises the module
        'entry_point_name =',
        # advertises a class from the module
        'entry_point_name =',

Note: entry points are part of the arguments of the setup function and needs to be passed to it as showed in the template.

In the context of gnomon we will only be advertising modules, the group name is the abstract base class minus the gnomonAbstract part and the entry point name should be the same name as the module name and the class name of the plugin.

For example, if we were to register a plugin called downsampleFilter which implements the abstract base class gnomonAbstractImageFilter and is located in src/plugin_name/algorithm we would get:

entry_points = {
    'imageFilter': [
        'downsampleFilter = plugin_name.algorithm.downsampleFilter',

There are two special entry points’ group: console_scripts and gui_scripts which we won’t be using here.


requires = ["setuptools"]
build-backend = "setuptools.build_meta"

source = ["src"]
omit = ["*", "test/*", ""]

omit = ["*", "test/*", ""]

Package installation

At the root of the package

  • activate your local environment e.g.: conda activate gnomon-x

  • run pip install .

You can check that everything is okay by importing your package in your python interpreter:

  python -c "import plugin_name; print(plugin_name)"

Adding unit tests

Each plugin should be tested

  • add a test/ folder at the root of the package

  • write one module per plugin, defining a test class inheriting unittest.TestCase

  • the test_XXX methods should check that the plugin runs without errors and generates the expected output

  • if necessary, you may add a resources folder with (small !) sample data to run your tests on

│   ...
│   │   ...
    │   │   ...

Building and Publishing a conda package

We need to set up 2 files in order to build a package: and meta.yaml. In addition to that we will also use an env.yaml file to define our working environment.

Defining an environment: env.yaml

Conda can save the state of an environment in a .yaml file and then create an environment from it. This is useful as it helps to have a consistent environment when developing, especially if one wants to build from source. Getting the environment setup becomes as easy as:

git clone
cd gnomon-package-pkgname
conda env create -f conda/env.yaml

There are two ways to make an env.yaml file:

  1. by exporting an existing env with conda env export

  2. by hand

In this section we will look at the second method.

An env.yaml file looks as follows:

name: gnomon-package-pkgname
  - gnomon
  - mosaic
  - morpheme
  - dtk-forge6
  - conda-forge
  - python=3.9
  - gnomon>=1.0.1
  - gnomon_package_data
  - ipython
  - nose2
  - coverage
  - importlib_metadata
  - numpy
  - pip:
      - pandas

There are three parts in it:

  1. name which will be the default name of the package (a new name can be used at install time with conda env create -f conda/env.yaml -n new_name).

  2. channels which are the channels from which to pull the dependencies.

  3. dependencies which lists the dependencies that needs to be installed. Dependencies can also be pulled from PyPI by specifying them in the - pip: part.

Metadata file (recipe): meta.yaml

This is where the package metadata is defined as well as data regarding how the package should be built. Here is an example from the package gnomon_package_tissueimage:

  name: gnomon_package_tissueimage
  version: {{ environ.get('GIT_DESCRIBE_TAG', 'default') }}

  path: ../

  number: {{ GIT_DESCRIBE_NUMBER }}
  preserve_egg_dir: True

    - pip
    - python=3.9
    - python=3.9
    - python=3.9
    - gnomon>=1.0.1
    - gnomon_package_data
    - ipython
    - nose2
    - coverage
    - matplotlib-base
    - numpy
    - pandas
    - scikit-learn
    - timagetk=3
    - ctrl
    - cellcomplex
    - importlib_metadata

  license: LGPL-3.0
  license_file: LICENSE
  summary: Gnomon python plugins to represent and manipulate 3D images

As you can see jinja2 templating can be used here.


In this section the package name and version are defined. Here we use the template {{ environ.get('GIT_DESCRIBE_TAG', 'default') }} to get the tag from git if you’re using git to hold the version. Otherwise put the version manually.


We only have one source and it is local. The path should be the relative path to the root of the package where the is located.


For a pure python package this section should stay the same.

The line preserve_egg_dir: True must be there.


In this section we define the different requirements needed to build, to link and to run. There are three sections which basically go like this:

  • build: what packages are needed in order to build the package

  • host: what packages should be linked in the destination platform

  • run: what packages are needed at runtime

More information on the definition of meta.yaml here.

Build script:

This one is rather easy. It is simply the bash script that needs to be called in order to build what needs to be packaged, in our case a python package.

The content should therefor simply be:

pip install .


conda build . -c conda-forge -c gnomon -c mosaic -c morpheme -c dtk-forge6