craft_parts.plugins.validator module

Definitions and helpers for plugin environment validation.

craft_parts.plugins.validator.COMMAND_NOT_FOUND = 127

The shell error code for command not found.

class craft_parts.plugins.validator.PluginEnvironmentValidator(*, part_name, env, properties)[source]

Bases: object

Base class for plugin environment validators.

Plugins may require certain environment elements to be present in order to build a part, regardless of how these elements were installed on the system. For example, a compiler may have been installed from a deb package, a snap, built from sources or even built by a different part. Plugin environment validators allow a plugin to ensure its execution environment is correct before building a part.

Parameters:
  • part_name (str) – The part whose build environment is being validated.

  • env (str) – A string containing the build step environment setup.

  • properties (PluginProperties) –

validate_dependency(dependency, plugin_name, part_dependencies, argument='--version')[source]

Validate that the environment has a required dependency.

<dependency-name> –version is executed to confirm the dependency is valid.

Parameters:
  • dependency (str) – name of the dependency to validate.

  • plugin_name (str) – used to generate the part name that would satisfy the dependency.

  • part_dependencies (Optional[List[str]]) – A list of the parts this part depends on.

  • argument (str) – argument to call with the dependency. Default is –version.

Raises:

PluginEnvironmentValidationError – If the environment is invalid.

Return type:

str

Returns:

output from executed dependency

validate_environment(*, part_dependencies=None)[source]

Ensure the plugin execution environment is valid.

The environment is verified twice: during the execution prologue after build packages and snaps are installed (to provide an early error message if the environment is invalid), and before running the build step for the part. During the prologue validation the environment may be incomplete, so we pass a list of the part dependencies as a hint of which parts may be used to build the environment.

Parameters:

part_dependencies (Optional[List[str]]) – A list of the parts this part depends on, so the validator can check if the required environment elements are supplied by another part when the method is called from the execution prologue. If the validation fails and list is empty, the error is final (the missing elements can’t be supplied by a different part). The plugin may require a specific part name as a hint that the part will attempt to supply missing environment elements.

Raises:

PluginEnvironmentValidationError – If the environment is invalid.

Return type:

None