Extending Nile with plugins

Nile can extend its CLI and Nile Runtime Environment functionalities through plugins. You can fork this example template and implement your desired functionality with the provided instructions.

How it works

This implementation takes advantage of the native extensibility features of Click. Using Click and leveraging Python entry points, we have a simple way of natively handling extensions in Python environments through dependencies. The plugin implementation on Nile looks for specific Python entry point constraints for adding commands to either the CLI or NRE.

  1. Use Click if the plugin provides a CLI command:

    # First, import click dependency
    import click
    # Decorate the method that will be the command name with `click.command`
    # Custom parameters can be added as defined in `click`: https://click.palletsprojects.com/en/7.x/options/
    def greet():
        Plugin CLI command that does something.
        # Done! Now implement the custom functionality in the command
        click.echo("Hello Nile!")
  2. Define the plugin entry points (in this case, by using the Poetry plugins feature in the pyproject.toml file):

    # We need to specify that Click commands are entry points in the group `nile_plugins`
    # <command_name> = <package_method_location>
    "greet" = "nile_greet.main.greet"
  3. Optionally specify plugin entry points for the Nile Runtime Environment. This doesn’t require implementing a Click command (remove the cli entry points if not needed):

    "greet" = "nile_greet.main.greet"
    "greet" = "nile_greet.nre.greet"
  4. Done! To better understand python entry points through setuptools, check this documentation.

How to decide if you want to use a plugin or not? Just install / uninstall the plugin dependency from your project 😄.

Using both cli and nre entry points under the nile_plugins group allows the development of powerful plugins which are easily integrated.