How to use the snapcraft.internal.steps.PRIME function in snapcraft

To help you get started, we’ve selected a few snapcraft examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github snapcore / snapcraft / tests / unit / pluginhandler / test_pluginhandler.py View on Github external
def test_prime_not_dirty_if_clean(self):
        self.assertTrue(
            self.handler.is_clean(steps.PRIME),
            "Expected vanilla handler to have clean prime step",
        )
        self.assertFalse(
            self.handler.is_dirty(steps.PRIME),
            "Expected vanilla handler to not have a dirty prime step",
        )
github snapcore / snapcraft / tests / unit / test_steps.py View on Github external
]

    def test_next_steps(self):
        self.assertThat(self.step.next_steps(), Equals(self.expected_steps))


class PreviousStepsTestCase(unit.TestCase):

    scenarios = [
        ("pull", {"step": steps.PULL, "expected_steps": []}),
        ("build", {"step": steps.BUILD, "expected_steps": [steps.PULL]}),
        ("stage", {"step": steps.STAGE, "expected_steps": [steps.PULL, steps.BUILD]}),
        (
            "prime",
            {
                "step": steps.PRIME,
                "expected_steps": [steps.PULL, steps.BUILD, steps.STAGE],
            },
        ),
    ]

    def test_previous_steps(self):
        self.assertThat(self.step.previous_steps(), Equals(self.expected_steps))
github snapcore / snapcraft / tests / unit / lifecycle / test_lifecycle.py View on Github external
def test_clean_leaves_prime_alone_for_tried(self, mock_for_root):
        project_config = self.make_snapcraft_project(
            textwrap.dedent(
                """\
                parts:
                  test-part:
                    plugin: nil
                """
            )
        )
        lifecycle.execute(steps.PRIME, project_config)
        lifecycle.clean(project_config.project, parts=None)
        self.assertThat(
            steps.PRIME.name,
            DirExists(),
            "Expected prime directory to remain after cleaning for tried snap",
        )
github snapcore / snapcraft / tests / unit / lifecycle / test_order.py View on Github external
"expected_dirty": [],
            },
        ),
        (
            "prime -> repull",
            {
                "initial_step": steps.PRIME,
                "initial_parts": ["main"],
                "test_parts": ["main"],
                "test_step": steps.PULL,
                "expected_initial": prime_order("main"),
                "expected_test": pull_order("main"),
                "expected_test_cleaned": [
                    dict(part="main", step=steps.BUILD),
                    dict(part="main", step=steps.STAGE),
                    dict(part="main", step=steps.PRIME),
                ],
                "expected_final": pull_order("main"),
                "expected_dirty": [],
            },
        ),
        # All  re-pull tests
        (
            "all pull -> repull",
            {
                "initial_step": steps.PULL,
                "initial_parts": [],
                "test_parts": ["main"],
                "test_step": steps.PULL,
                "expected_initial": pull_order(),
                "expected_test": pull_order("main"),
                "expected_test_cleaned": [
github snapcore / snapcraft / tests / unit / pluginhandler / test_pluginhandler.py View on Github external
def test_prime_is_outdated(self):
        self.handler.mark_prime_done(set(), set(), set(), set())
        self.assertFalse(
            self.handler.is_outdated(steps.PRIME),
            "Prime step was unexpectedly outdated",
        )

        # Now mark the stage state as done, but ensure it has a later
        # timestamp, thereby making the prime step out of date.
        prime_state_path = states.get_step_state_file(
            self.handler.plugin.statedir, steps.PRIME
        )
        stage_state_path = states.get_step_state_file(
            self.handler.plugin.statedir, steps.STAGE
        )
        open(stage_state_path, "w").close()
        self.set_modified_time_later(stage_state_path, prime_state_path)

        self.assertTrue(
            self.handler.is_outdated(steps.PRIME), "Expected prime step to be outdated"
        )
github snapcore / snapcraft / tests / unit / pluginhandler / test_pluginhandler.py View on Github external
def test_stage(self):
        self.assertRaises(errors.NoLatestStepError, self.handler.latest_step)
        self.assertThat(self.handler.next_step(), Equals(steps.PULL))

        self.handler.stage()

        self.assertThat(self.handler.latest_step(), Equals(steps.STAGE))
        self.assertThat(self.handler.next_step(), Equals(steps.PRIME))
github snapcore / snapcraft / tests / unit / project_loader / inspection / test_lifecycle_status.py View on Github external
"stage": "complete",
                        "prime": "complete",
                    },
                    {
                        "part": "part2",
                        "pull": "outdated (source changed)",
                        "build": "complete",
                        "stage": "complete",
                        "prime": "complete",
                    },
                ]
            ),
        )

        # Now clean the prime step of part1 and verify that it effects part2
        self.part1.mark_cleaned(steps.PRIME)
        self.assertThat(
            inspection.lifecycle_status(self.config),
            Equals(
                [
                    {
                        "part": "part1",
                        "pull": "complete",
                        "build": "complete",
                        "stage": "complete",
                        "prime": None,
                    },
                    {
                        "part": "part2",
                        "pull": "outdated (source changed)",
                        "build": "complete",
                        "stage": "complete",
github snapcore / snapcraft / snapcraft / internal / lifecycle / _clean.py View on Github external
else:
            remove_dir = False
            message = (
                "Cleaning up priming area, but not removing as it's in "
                "use by 'snap try'"
            )
            being_tried = True
        finally:
            # It does not matter if prime is being tried inside the managed-host
            # or not, we cannot delete prime as it is really a mount from the
            # outside host.
            if project._is_managed_host:
                remove_dir = False
                message = None
        _cleanup_common(
            project.prime_dir, steps.PRIME, message, parts, remove_dir=remove_dir
        )

    if step <= steps.STAGE:
        # Remove the staging area.
        _cleanup_common(
            project.stage_dir, steps.STAGE, "Cleaning up staging area", parts
        )

    if step <= steps.PULL:
        # Remove the parts directory (but leave local plugins alone).
        _cleanup_parts_dir(project.parts_dir, project.local_plugins_dir, parts)

    if not being_tried and not project._is_managed_host:
        _remove_directory_if_empty(project.prime_dir)
    _remove_directory_if_empty(project.stage_dir)
    _remove_directory_if_empty(project.parts_dir)
github snapcore / snapcraft / snapcraft / internal / project_loader / inspection / _provides.py View on Github external
def _part_states_for_step(
    step: steps.Step, parts: Iterable[pluginhandler.PluginHandler]
) -> Iterable[
    Tuple[pluginhandler.PluginHandler, Union[states.StageState, states.PrimeState]]
]:
    state_getter: Optional[
        Callable[
            [pluginhandler.PluginHandler], Union[states.StageState, states.PrimeState]
        ]
    ] = None

    if step == steps.STAGE:
        state_getter = pluginhandler.PluginHandler.get_stage_state
    elif step == steps.PRIME:
        state_getter = pluginhandler.PluginHandler.get_prime_state
    else:
        # This is programmer error
        raise RuntimeError("Only the stage or prime step is supported!")

    for part in parts:
        state = state_getter(part)
        if state:
            yield (part, state)
github snapcore / snapcraft / snapcraft / internal / lifecycle / _runner.py View on Github external
def _rerun_step(self, *, step: steps.Step, part, progress, hint=""):
        staged_state = self.config.get_project_state(steps.STAGE)
        primed_state = self.config.get_project_state(steps.PRIME)

        # First clean the step, then run it again
        part.clean(staged_state, primed_state, step)

        # Uncache this and later steps since we just cleaned them: their status
        # has changed
        for current_step in [step] + step.next_steps():
            self._cache.clear_step(part, current_step)

        self._run_step(step=step, part=part, progress=progress, hint=hint)