LifecycleService¶
The LifecycleService handles interactions with Craft Parts.
API documentation¶
- class craft_application.services.lifecycle.LifecycleService¶
Create and manage the parts lifecycle.
- Parameters:
app – An AppMetadata object containing metadata about the application.
project – The Project object that describes this project.
work_dir – The working directory for parts processing.
cache_dir – The cache directory for parts processing.
build_plan – The filtered build plan of platforms that are valid for the running host.
lifecycle_kwargs – Additional keyword arguments are passed through to the LifecycleManager on initialisation.
- __init__(app: AppMetadata, services: ServiceFactory, *, work_dir: Path | str, cache_dir: Path | str, **lifecycle_kwargs: Any) None¶
- setup() None¶
Initialize the LifecycleManager with previously-set arguments.
- static get_plugin_group(build_info: craft_platforms.BuildInfo) dict[str, type[Plugin]] | None¶
Get the plugin group for a given build.
If this returns a non-
Nonevalue, the LifecycleService sets the plugin group to that group when running the given build. IfNoneis returned, the plugin groups feature is not used and an application must manually handle its plugin groups.The default implementation simply returns
None, as this is designed for an application to override in order to get the relevant plugin groups.- Parameters:
build_info – The BuildInfo for the build.
- Returns:
A dictionary that is an appropriate plugin group or
None.
- _validate_build_plan() None¶
Validate that the build plan is usable for a lifecycle run.
- _get_build_for() str¶
Get the
build_forarchitecture for craft-parts.The default behaviour is as follows: 1. If the build plan’s
build_forisall, use the host architecture. 2. If it’s anything else, use that. 3. If it’s undefined, use the host architecture.
- _init_lifecycle_manager() LifecycleManager¶
Create and return the Lifecycle manager.
An application may override this method if needed if the lifecycle manager needs to be called differently.
- property prime_state_timestamp: float | None¶
The timestamp of the most recently primed part’s prime state file.
- property prime_dir: Path¶
The path to the prime directory.
- property project_info: ProjectInfo¶
The lifecycle’s ProjectInfo.
- get_pull_assets(*, part_name: str) dict[str, Any] | None¶
Obtain the part’s pull state assets.
- Parameters:
part_name – The name of the part to get assets from.
- Returns:
The dictionary of the part’s pull assets, or None if no state found.
- get_primed_stage_packages(*, part_name: str) list[str] | None¶
Obtain the list of primed stage packages.
- Parameters:
part_name – The name of the part to get primed stage packages from.
- Returns:
The sorted list of primed stage packages, or None if no state found.
- run(step_name: str | None, part_names: list[str] | None = None) None¶
Run the lifecycle manager for the parts.
- Parameters:
step_name – The name of the target step (defaults to running the entire lifecycle)
part_names – Which parts to build (defaults to all parts)
- post_prime(step_info: StepInfo) bool¶
Perform any necessary post-lifecycle modifications to the prime directory.
This method should be idempotent and meet the requirements for a craft-parts callback. It is added as a post-prime callback during the setup phase.
NOTE: This is not guaranteed to run in any particular order if other callbacks are added to the prime step.
- clean(part_names: list[str] | None = None) None¶
Remove lifecycle artifacts.
- Parameters:
part_names – The names of the parts to clean. If unspecified, all parts will be cleaned.
- static previous_step_name(step_name: str) str | None¶
Get the name of the step immediately previous to step_name.
Returns None if step_name is the first one (pull).