craft_parts.callbacks module

Register and execute callback functions.

class craft_parts.callbacks.CallbackHook(function, step_list)

Bases: tuple

function

Alias for field number 0

step_list

Alias for field number 1

craft_parts.callbacks.get_stage_packages_filters(project_info)[source]

Obtain the list of stage packages to be filtered out.

Parameters:

project_info (ProjectInfo) – The project information to be sent to callback functions.

Return type:

Optional[Set[str]]

Returns:

An iterator for the list of packages to be filtered out.

craft_parts.callbacks.register_configure_overlay(func)[source]

Register a callback function to configure the mounted overlay.

This “hook” is called after the overlay’s package cache layer is mounted, but before the package list is refreshed. It can be used to configure the overlay’s system, typically to install extra package repositories for Apt. Note that when the hook is called the overlay is mounted but not chroot’ed into.

Parameters:

func (Callable[[Path, ProjectInfo], None]) – The callback function that will be called with the location of the overlay mount and the project info.

Return type:

None

craft_parts.callbacks.register_epilogue(func)[source]

Register an execution epilogue callback function.

Parameters:

func (Callable[[ProjectInfo], None]) – The callback function to run.

Return type:

None

craft_parts.callbacks.register_post_step(func, *, step_list=None)[source]

Register a post-step callback function.

Parameters:
  • func (Callable[[StepInfo], bool]) – The callback function to run.

  • step_list (Optional[List[Step]]) – The steps after which the callback function should run. If not specified, the callback function will be executed after all steps.

Return type:

None

craft_parts.callbacks.register_pre_step(func, *, step_list=None)[source]

Register a pre-step callback function.

Parameters:
  • func (Callable[[StepInfo], bool]) – The callback function to run.

  • step_list (Optional[List[Step]]) – The steps before which the callback function should run. If not specified, the callback function will be executed before all steps.

Return type:

None

craft_parts.callbacks.register_prologue(func)[source]

Register an execution prologue callback function.

Parameters:

func (Callable[[ProjectInfo], None]) – The callback function to run.

Return type:

None

craft_parts.callbacks.register_stage_packages_filter(func)[source]

Register a callback function for stage packages dependency cutoff.

Craft Parts includes mechanisms to filter out stage package dependencies in snap bases. This is now deprecated, and a function providing an explicit list of exclusions should be provided by the application.

Parameters:

func (Callable[[ProjectInfo], Iterable[str]]) – The callback function returning the filtered packages iterator.

Return type:

None

craft_parts.callbacks.run_configure_overlay(overlay_dir, project_info)[source]

Run all registered ‘configure overlay’ callbacks.

Parameters:
  • overlay_dir (Path) – The location where the overlay is mounted.

  • project_info (ProjectInfo) – The project information to be sent to callback functions.

Return type:

None

craft_parts.callbacks.run_epilogue(project_info)[source]

Run all registered execution epilogue callbacks.

Parameters:

project_info (ProjectInfo) – The project information to be sent to callback functions.

Return type:

None

craft_parts.callbacks.run_post_step(step_info)[source]

Run all registered post-step callback functions.

Parameters:

step_info (StepInfo) – the step information to be sent to the callback functions.

Return type:

None

craft_parts.callbacks.run_pre_step(step_info)[source]

Run all registered pre-step callback functions.

Parameters:

step_info (StepInfo) – the step information to be sent to the callback functions.

Return type:

None

craft_parts.callbacks.run_prologue(project_info)[source]

Run all registered execution prologue callbacks.

Parameters:

project_info (ProjectInfo) – The project information to be sent to callback functions.

Return type:

None

craft_parts.callbacks.unregister_all()[source]

Clear all existing registered callback functions.

Return type:

None