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

::...

免责声明:
当前网页内容, 由 大妈 ZoomQuiet 使用工具: ScrapBook :: Firefox Extension 人工从互联网中收集并分享;
内容版权归原作者所有;
本人对内容的有效性/合法性不承担任何强制性责任.
若有不妥, 欢迎评注提醒:

或是邮件反馈可也:
askdama[AT]googlegroups.com


订阅 substack 体验古早写作:


点击注册~> 获得 100$ 体验券: DigitalOcean Referral Badge

关注公众号, 持续获得相关各种嗯哼:
zoomquiet


自怼圈/年度番新

DU22.4
关于 ~ DebugUself with DAMA ;-)
粤ICP备18025058号-1
公安备案号: 44049002000656 ...::