Package reference

Architectures

class craft_platforms.DebianArchitecture(value)[source]

A Debian architecture.

classmethod from_machine(arch)[source]

Get a DebianArchitecture value from the given platform arch.

Parameters:

arch (str) – a string containing an architecture as returned by platform.machine()

Returns:

Self – The DebianArchitecture enum value

Raises:

ValueError if the architecture is not a valid Debian architecture.

classmethod from_host()[source]

Get the DebianArchitecture of the running host.

Return type:

Self

to_platform_arch()[source]

Convert this DebianArchitecture to a platform string.

Returns:

str – A string matching what platform.machine() or uname -m would return.

to_efi_arch()[source]

Convert this DebianArchitecture to an EFI firmware string.

Returns:

str – A string as matched by UKIFY in systemd (see https://github.com/systemd/systemd/blob/main/src/ukify/ukify.py)

to_grub_arch()[source]

Convert this DebianArchitecture to a GRUB boot target.

Returns:

str – A string suitable for the –target argument to grub-install

Build plans

class craft_platforms.BuildInfo(platform, build_on, build_for, build_base)[source]

Platform build information.

Parameters:
platform

Type:    str

The platform name.

build_on

Type:    DebianArchitecture

The architecture to build on.

build_for

Type:    Union[DebianArchitecture, Literal['all']]

The architecture to build for.

build_base

Type:    DistroBase

The base to build on.

craft_platforms.get_platforms_build_plan(base, platforms, build_base=None, *, allow_all_and_architecture_dependent=False)[source]

Generate the build plan for a platforms-based artifact.

Parameters:
  • base (str | DistroBase) – The target base

  • platforms (Dict[DebianArchitecture | str, PlatformDict | None]) – A dictionary of the platforms.

  • build_base (str | None, default: None) – The build base, if declared.

  • allow_all_and_architecture_dependent (bool, default: False) – whether to allow architecture-dependent platforms and architecture-independent platforms to coexist. This does not change the fact that only one architecture-independent platform can exist.

Return type:

Sequence[BuildInfo]

craft_platforms.get_build_plan(app, *, project_data, strict_platform_names=False, allow_app_characters=False)[source]

Get a build plan for a given application.

Parameters:
  • app (str) – The name of the application (e.g. snapcraft, charmcraft, rockcraft)

  • project_data (Dict[str, Any]) – The raw dictionary of the project’s YAML file. Normally this is what’s output from yaml.safe_load().

  • strict_platform_names (bool, default: False) – Whether to strictly validate all platform names.

  • allow_app_characters (bool, default: False) – Whether platform name validation allows characters that are reserved for use by applications.

Returns:

Iterable[BuildInfo] – An iterable containing each possible BuildInfo for this file.

Raises:

InvalidPlatformNameError if strict validation is turned on and a platform name is incorrect.

This function is an abstraction layer over the general build planners, taking the application’s name and its raw data and returning an exhaustive build plan for the given project for that application. This allows craft-platforms to be used in a forward-compatible manner as it adds more logic around selecting build planners or special behaviour for more apps.

Distributions

class craft_platforms.BaseName(*args, **kwargs)[source]

A protocol for any class that can be used as an OS base.

This protocol exists as a backwards compatibility shim for the language used in craft-providers.

class craft_platforms.DistroBase(distribution, series)[source]

A linux distribution base.

Parameters:
  • distribution (str)

  • series (str)

classmethod from_str(base_str)[source]

Parse a distribution string to a DistroBase.

Parameters:

base_str (str) – A distribution string (e.g. “ubuntu@24.04”)

Returns:

Self – A DistroBase of this string.

Raises:

ValueError if the string isn’t of the appropriate format.

classmethod from_linux_distribution(distribution)[source]

Convert a distro package’s LinuxDistribution object to a DistroBase.

Parameters:

distribution (LinuxDistribution) – A LinuxDistribution from the distro package.

Returns:

Self – A matching DistroBase object.

classmethod from_host()[source]

Get the Linux distribution where this process is running.

Return type:

Self

craft_platforms.is_ubuntu_like(distribution=None)[source]

Determine whether the given distribution is Ubuntu or Ubuntu-like.

Parameters:

distribution (LinuxDistribution | None, default: None) – Linux distribution info object, or None to use the host system.

Returns:

bool – A boolean noting whether the given distribution is Ubuntu or Ubuntu-like.