7.10. Creating a junifer plugin¶
7.10.1. What is a plugin¶
Plugins are additional components that extend the functionality of junifer.
Technically, plugins can also be called as extensions, but we clearly differentiate
them in junifer as extensions serve a different
purpose. junifer plugins are command line programs which can be used
independently but also integrates with the core junifer command line interface
(CLI) framework.
When a plugin is installed, we basically inject new behaviours into the junifer CLI
while promoting modularity and allowing for easier maintenance and updates to the core
application. A great plugin example is junifer-data which is well-integrated
in junifer to access assets like parcellations, coordinates and masks, but also
remains modular enough to update its CLI without disturbing that of junifer.
7.10.2. How to make a plugin¶
A key distinction between a junifer extension and a junifer plugin is that a
plugin will have its own CLI and be a Python package in its own right, for example,
junifer-data.
The following steps should lead you to make a successful plugin:
Create CLI for your plugin. As
juniferuses click for its CLI, a plugin should be creating its ownclick.Groupas shown here: https://click.palletsprojects.com/en/stable/commands/#commands-and-groups.Integrate the click-based plugin CLI with setuptools as shown here: https://click.palletsprojects.com/en/stable/setuptools/#setuptools-integration.
Make sure the plugin CLI independently works as intended.
Follow the steps here: https://setuptools.pypa.io/en/latest/userguide/entry_point.html#entry-points-for-plugins and make a new entry point with the name as the sub-command you want under
junifercommand and the group as"junifer.ext". The name should refer to theclick.Groupof your plugin CLI.After you install your plugin in the same environment as your
juniferinstallation, you can observe your plugin being added as a new sub-command underjuniferand working exactly as it did independently.