# -*- Mode:Python; indent-tabs-mode:nil; tab-width:4 -*-## Copyright 2021-2023 Canonical Ltd.## This program is free software; you can redistribute it and/or# modify it under the terms of the GNU Lesser General Public# License version 3 as published by the Free Software Foundation.## This program is distributed in the hope that it will be useful,# but WITHOUT ANY WARRANTY; without even the implied warranty of# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU# Lesser General Public License for more details.## You should have received a copy of the GNU Lesser General Public License# along with this program. If not, see <http://www.gnu.org/licenses/>."""Definitions and helpers to handle lifecycle steps."""importenumfromcraft_parts.featuresimportFeatures
[docs]@enum.uniqueclassStep(enum.IntEnum):"""All the steps needed to fully process a part. Steps correspond to the tasks that must be fulfilled in order to process each of the parts in the project specification. In the ``PULL`` step sources for a part are retrieved and unpacked. The ``OVERLAY`` step is used to change the underlying filesystem. In the ``BUILD`` step artifacts are built and installed. In the ``STAGE`` step installed build artifacts from all parts and overlay contents are added to a staging area. These files are further processed in the ``PRIME`` step to obtain the final tree with the final payload for deployment. """PULL=1OVERLAY=2BUILD=3STAGE=4PRIME=5def__repr__(self)->str:returnf"{self.__class__.__name__}.{self.name}"
[docs]defprevious_steps(self)->list["Step"]:"""List the steps that should happen before the current step. :returns: The list of previous steps. """steps=[]ifself>=Step.OVERLAY:steps.append(Step.PULL)ifself>=Step.BUILDandFeatures().enable_overlay:steps.append(Step.OVERLAY)ifself>=Step.STAGE:steps.append(Step.BUILD)ifself>=Step.PRIME:steps.append(Step.STAGE)returnsteps
[docs]defnext_steps(self)->list["Step"]:"""List the steps that should happen after the current step. :returns: The list of next steps. """steps=[]ifself==Step.PULLandFeatures().enable_overlay:steps.append(Step.OVERLAY)ifself<=Step.OVERLAY:steps.append(Step.BUILD)ifself<=Step.BUILD:steps.append(Step.STAGE)ifself<=Step.STAGE:steps.append(Step.PRIME)returnsteps
[docs]defdependency_prerequisite_step(step:Step)->Step|None:"""Obtain the step a given step may depend on. :returns: The prerequisite step. """# With V2 plugins we don't need to repull if dependency is restagedifstep<=Step.OVERLAY:returnNoneifstep<=Step.STAGE:returnStep.STAGEreturnstep