craft_parts.plugins.plugins module

Definitions and helpers to handle plugins.

class craft_parts.plugins.plugins.PluginGroup(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: Enum

Plugin groups available for use.

DEFAULT = {'ant': <class 'craft_parts.plugins.ant_plugin.AntPlugin'>, 'autotools': <class 'craft_parts.plugins.autotools_plugin.AutotoolsPlugin'>, 'cargo-use': <class 'craft_parts.plugins.cargo_use_plugin.CargoUsePlugin'>, 'cmake': <class 'craft_parts.plugins.cmake_plugin.CMakePlugin'>, 'dotnet': <class 'craft_parts.plugins.dotnet_plugin.DotnetPlugin'>, 'dump': <class 'craft_parts.plugins.dump_plugin.DumpPlugin'>, 'go': <class 'craft_parts.plugins.go_plugin.GoPlugin'>, 'go-use': <class 'craft_parts.plugins.go_use_plugin.GoUsePlugin'>, 'gradle': <class 'craft_parts.plugins.gradle_plugin.GradlePlugin'>, 'jlink': <class 'craft_parts.plugins.jlink_plugin.JLinkPlugin'>, 'make': <class 'craft_parts.plugins.make_plugin.MakePlugin'>, 'maven': <class 'craft_parts.plugins.maven_plugin.MavenPlugin'>, 'maven-use': <class 'craft_parts.plugins.maven_use_plugin.MavenUsePlugin'>, 'meson': <class 'craft_parts.plugins.meson_plugin.MesonPlugin'>, 'nil': <class 'craft_parts.plugins.nil_plugin.NilPlugin'>, 'npm': <class 'craft_parts.plugins.npm_plugin.NpmPlugin'>, 'poetry': <class 'craft_parts.plugins.poetry_plugin.PoetryPlugin'>, 'python': <class 'craft_parts.plugins.python_plugin.PythonPlugin'>, 'qmake': <class 'craft_parts.plugins.qmake_plugin.QmakePlugin'>, 'ruby': <class 'craft_parts.plugins.ruby_plugin.RubyPlugin'>, 'rust': <class 'craft_parts.plugins.rust_plugin.RustPlugin'>, 'scons': <class 'craft_parts.plugins.scons_plugin.SConsPlugin'>, 'uv': <class 'craft_parts.plugins.uv_plugin.UvPlugin'>}

The default set of plugins for most use cases.

The plugins in this group are generally considered functional on most legacy bases.

MINIMAL = {'dump': <class 'craft_parts.plugins.dump_plugin.DumpPlugin'>, 'nil': <class 'craft_parts.plugins.nil_plugin.NilPlugin'>}

A completely minimal set of plugins.

The plugins in this group are required for all applications.

craft_parts.plugins.plugins.extract_part_properties(data, *, plugin_name)[source]

Get common part properties without plugin-specific entries.

Parameters:
  • data (dict[str, Any]) – A dictionary containing all part properties.

  • plugin_name (str) – The name of the plugin.

Return type:

dict[str, Any]

Returns:

A dictionary containing only common part properties.

craft_parts.plugins.plugins.get_plugin(*, part, part_info, properties)[source]

Obtain a plugin instance for the specified part.

Parameters:
  • part (Part) – The part requesting the plugin.

  • part_info (PartInfo) – The part information data.

  • properties (PluginProperties) – The plugin properties.

Return type:

Plugin

Returns:

The plugin instance.

craft_parts.plugins.plugins.get_plugin_class(name)[source]

Obtain a plugin class given the name.

Parameters:

name (str) – The plugin name.

Return type:

type[Plugin]

Returns:

The plugin class.

Raises:

ValueError – If the plugin name is invalid.

craft_parts.plugins.plugins.get_registered_plugins()[source]

Return the list of currently registered plugins.

Return type:

dict[str, type[Plugin]]

craft_parts.plugins.plugins.register(plugins)[source]

Register part handler plugins.

Parameters:

plugins (dict[str, type[Plugin]]) – a dictionary where the keys are plugin names and values are plugin classes. Valid plugins must subclass class:Plugin.

Return type:

None

craft_parts.plugins.plugins.set_plugin_group(group)[source]

Set the plugin group to use.

This method replaces the group of registered plugins with the named plugin group.

Parameters:

group (Mapping[str, type[Plugin]] | PluginGroup) – The name of the plugin group or the instance thereof.

Return type:

None

craft_parts.plugins.plugins.unregister(*plugins)[source]

Unregister plugins by name.

Parameters:

plugins (str)

Return type:

None

craft_parts.plugins.plugins.unregister_all()[source]

Unregister all user-registered plugins.

Return type:

None

craft_parts.plugins.plugins.validate_and_extract(data, *, plugin_name)[source]

Validate plugin-related attributes and extract common part properties.

Parameters:
  • data (dict[str, Any]) – A dictionary containing all part properties.

  • plugin_name (str) – The name of the plugin.

Return type:

dict[str, Any]

Returns:

A dictionary containing only common part properties.

craft_parts.plugins.plugins.validate_build_attributes(data, *, plugin_name)[source]

Validate that the build-attributes are compatible with the plugin.

Parameters:
  • data (dict[str, Any])

  • plugin_name (str)

Return type:

None