Plugins

You may wish to alter or expand Poetry's functionality with your own. For example if your environment poses special requirements on the behaviour of Poetry which do not apply to the majority of its users or if you wish to accomplish something with Poetry in a way that is not desired by most users.

In these cases you could consider creating a plugin to handle your specific logic.

Creating a plugin

A plugin is a regular Python package which ships its code as part of the package and may also depend on further packages.

Plugin package

The plugin package must depend on Poetry and declare a proper plugin in the pyproject.toml file.

[tool.poetry]
name = "my-poetry-plugin"
version = "1.0.0"
# ...

[tool.poetry.dependency]
python = "~2.7 || ^3.7"
poetry = "^1.0"

[tool.poetry.plugins."poetry.plugin"]
demo = "poetry_demo_plugin.plugin:MyPlugin"

Plugin class

Every plugin has to supply a class which implements the poetry.plugins.Plugin interface.

The activate() method of the plugin is called after the plugin is loaded and receives an instance of Poetry as well as an instance of clikit.api.io.IO.

Using these two objects all configuration can be read and all internal objects and state can be manipulated as desired.

Example:

from poetry.plugins import Plugin


class MyPlugin(Plugin):

    def activate(self, poetry, io):  # type: (Poetry, IO) -> None
        version = self.get_custom_version()
        io.write_line("Setting package version to {}".format(version))

        poetry.package.version = version

    def get_custom_version(self):  # type: () -> str
        ...