Poetry plugin

The Poetry plugin can be used for Python projects that use the Poetry build system.

Keywords

This plugin uses the common plugin keywords as well as those for sources.

Additionally, this plugin provides the plugin-specific keywords defined in the following sections.

poetry-with:

Type: list of strings

Extra dependency groups to use other than the defaults.

Environment variables

This plugin also sets environment variables in the build environment. User-set environment variables will override these values. Users may also set environment variables to configure Poetry using the build-environment key.

PARTS_PYTHON_INTERPRETER

Default value: python3

Either the interpreter binary to search for in PATH or an absolute path to the interpreter (e.g. ${CRAFT_STAGE}/bin/python).

PARTS_PYTHON_VENV_ARGS

Default value: (empty string)

Additional arguments passed to python -m venv.

Dependencies

Whether the Python interpreter needs to be included in the snap depends on its confinement. Specifically:

  • Projects with strict or devmode confinement can safely use the base snap’s interpreter, so they typically do not need to include Python.

  • Projects with classic confinement cannot use the base snap’s interpreter and thus must always bundle it (typically via stage-packages).

  • In both cases, a specific/custom Python installation can always be included in the snap. This can be useful, for example, when using a different Python version or building an interpreter with custom flags.

Snapcraft will prefer an included interpreter over the base’s, even for projects with strict and devmode confinement.

How it works

During the build step, the plugin performs the following actions:

  1. It creates a virtual environment directly into the ${CRAFT_PART_INSTALL} directory.

  2. It uses poetry export to create a requirements.txt file in the project’s build directory.

  3. It uses pip to install the packages referenced in requirements.txt into the virtual environment, without any additional dependencies.

  4. It uses pip to install the source package without any additional dependencies.

  5. It runs pip check to ensure the virtual environment is consistent.