craft_parts.state_manager.state_manager module

Part crafter step state management.

class craft_parts.state_manager.state_manager.StateManager(*, project_info, part_list, ignore_outdated=None)[source]

Bases: object

Keep track of lifecycle execution state.

The State Manager tells whether a step should run based on current state information. The state database is initialized from state on disk, and after that it’s maintained only in memory.

Parameters:
  • project_info (ProjectInfo) – The project information.

  • part_list (list[Part]) – A list of this project’s parts.

  • ignore_outdated (Optional[list[str]]) – A list of file patterns to ignore when testing for outdated files.

check_if_dirty(part, step)[source]

Verify whether a step is dirty.

A step is considered to be dirty if relevant properties or project options have changed since the step was executed. This means the step needs to be cleaned and run again. This is in contrast to an “outdated” step, which typically doesn’t need to be cleaned, just updated with files from an earlier step in the lifecycle.

Parameters:
  • part (Part) – The part the step to be checked belongs to.

  • step (Step) – The step to be checked.

Return type:

DirtyReport | None

Returns:

A class:DirtyReport if the step is outdated, None otherwise.

check_if_outdated(part, step)[source]

Verify whether a step is outdated.

A step is considered to be outdated if an earlier step in the lifecycle has been run more recently, or if the source code changed on disk. This means the step needs to be updated by taking modified files from the previous step. This is in contrast to a “dirty” step, which must be cleaned and run again.

Parameters:
  • part (Part) – The part the step to be checked belongs to.

  • step (Step) – The step to be checked.

Return type:

OutdatedReport | None

Returns:

An class:OutdatedReport if the step is outdated, None otherwise.

clean_part(part, step)[source]

Remove the state for this and later steps in the given part.

Parameters:
  • part (Part) – The part corresponding to the state to remove.

  • step (Step) – The step corresponding to the state to remove.

Return type:

None

get_outdated_dirs(part)[source]

Get the list of outdated directories for this part.

Parameters:

part (Part) – The part being processed.

Return type:

list[str] | None

Returns:

The list of outdated directories from the part’s pull step.

get_outdated_files(part)[source]

Get the list of outdated files for this part.

Parameters:

part (Part) – The part being processed.

Return type:

list[str] | None

Returns:

The list of outdated files from the part’s pull step.

get_step_state_overlay_hash(part, step)[source]

Get the overlay hash from the step state.

Parameters:
  • part (Part) – The part being processed.

  • part – The step being processed.

  • step (Step)

Return type:

bytes

Returns:

The hash value for the layer corresponding to the part being processed.

has_step_run(part, step)[source]

Determine if a given step of a given part has already run.

Parameters:
  • part (Part) – The part the step to be verified belongs to.

  • step (Step) – The step to verify.

Return type:

bool

Returns:

Whether the step has already run.

mark_step_updated(part, step)[source]

Mark the given part and step as updated.

Parameters:
  • part (Part) – The part being processed.

  • part – The step being processed.

  • step (Step)

Return type:

None

project_vars(part, step)[source]

Obtain the project variables for a given part and step.

Parameters:
  • part (Part) – The part corresponding to the state to retrieve.

  • part – The step corresponding to the state to retrieve.

  • step (Step)

Return type:

dict[str, ProjectVar] | None

Returns:

The project variables from the last execution.

set_state(part, step, *, state)[source]

Set the state of the given part and step.

Parameters:
  • part (Part) – The part corresponding to the state to be set.

  • step (Step) – The step corresponding to the state to be set.

  • state (StepState)

Return type:

None

should_step_run(part, step)[source]

Determine if a given step of a given part should run.

A given step should run if:
  1. it hasn’t already run

  2. it’s dirty

  3. it’s outdated

  4. either (1), (2), or (3) apply to any earlier steps in the part’s lifecycle.

Parameters:
  • part (Part) – The part the step to be verified belongs to.

  • step (Step) – The step to verify.

Return type:

bool

Returns:

Whether the step should run.

update_state_timestamp(part, step)[source]

Mark the step as recently modified.

Parameters:
  • part (Part) – The part corresponding to the state to update.

  • step (Step) – The step corresponding to the state to update.

Return type:

None