craft_parts.plugins.python_v2.python_plugin module

Version 2 of the Python plugin.

class craft_parts.plugins.python_v2.python_plugin.PythonPlugin(*, properties, part_info)

Bases: Plugin

Python plugin, version 2.

Unlike the original Python plugin, this one does not require the creation of virtual environments to work. Instead, it uses pip’s support for both a) installing directly into the user’s base dir and b) using a Python interpreter that is not the one running pip initially. This allows lighter payloads as the -venv package is not required, and interacts well with usrmerged directories.

The downside is that the payload generated by the plugin assumes that the primed contents will include the Python interpreter; if this is not the case, the runtime will need to add the payload to Python’s path (e.g. via PYTHONPATH).

Parameters:
get_build_commands()

Return a list of commands to run during the build step.

Return type:

list[str]

get_build_environment()

Return a dictionary with the environment to use in the build step.

Return type:

dict[str, str]

get_build_packages()

Return a set of required packages to install in the build environment.

Return type:

set[str]

get_build_snaps()

Return a set of required snaps to install in the build environment.

Return type:

set[str]

properties_class

alias of PythonPluginProperties

class craft_parts.plugins.python_v2.python_plugin.PythonPluginProperties(**data)

Bases: PluginProperties

The part properties used by the python plugin.

Parameters:

data (Any)

model_config: ClassVar[ConfigDict] = {'alias_generator': <function PluginProperties.<lambda>>, 'extra': 'forbid', 'frozen': True, 'validate_assignment': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

plugin: Literal['python']
python_packages: list[str]

Additional Python packages to install with pip.

python_requirements: list[str]

List of paths to requirements files.

Use this key when dependencies must be installed from one or more explicit requirements files, such as requirements.txt. The plugin does not automatically select a requirements file from the source tree; each file must be listed here.

A part does not need this key when its dependencies are already declared by the project metadata used during package installation. For example, when the source contains a setup.py or pyproject.toml file, the plugin installs the project and pip resolves the dependencies declared by the package itself. That metadata may also come from configuration files such as setup.cfg.

source: str