Making a plugin¶
This section describes how to make a plugin for the Expipe command line interface (CLI). For the complete example; see https://github.com/CINPLA/expipe-plugin-example.
In order to make a plugin for the comman line interface you first need to make a python package.
Begin by making a folder named my_plugin
with a module, let’s call it
my_module.py
containing:
from expipe.cliutils import IPlugin
import click
class MyPlugin(IPlugin):
"""Create the `expipe print-me-stuff` command."""
def attach_to_cli(self, cli):
@cli.command('print-me-stuff')
@click.argument('stuff', type=click.STRING)
def print_me_stuff(stuff):
'''
Print stuff
COMMAND: stuff
'''
print(f'Expipe is printing: {stuff}')
The folder my_plugin
must also contain a file __init__.py
containing:
from .my_module import MyPlugin
In the root directory you need a setup.py
file with the
following minimum content:
from setuptools import setup
from setuptools import setup, find_packages
setup(
name="my_plugin",
packages=find_packages(),
include_package_data=True,
)
After the plugin package is ready, all you need to do is to install it and add it to the Expipe environment:
>>> python setup.py develop
>>> expipe config global --add plugin my_plugin
Finally, you can run your new incredible plugin with expipe:
>>> expipe print-me-stuff "Hey! This is my first Expipe plugin!"
Expipe is printing: Hey! This is my first Expipe plugin!