How to use the snapcraft.internal.lifecycle.execute 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 / lifecycle / test_order.py View on Github external
def run_test(self):
        lifecycle.execute(
            self.initial_step, self.project_config, part_names=self.initial_parts
        )

        initial_order = self.get_run_order()
        self.assert_run_order_equal(initial_order, self.expected_initial, "(initial)")

        lifecycle.execute(
            self.test_step, self.project_config, part_names=self.test_parts
        )

        current_order = self.get_run_order()
        test_order = [o for o in current_order if o not in initial_order]
        self.assert_run_order_equal(test_order, self.expected_test, "(test)")

        self.assert_parts_cleaned(
            initial_order, current_order, self.expected_test_cleaned, "(cleaned)"
github snapcore / snapcraft / tests / unit / lifecycle / test_snap_installation.py View on Github external
def test_part_with_build_snaps(self, mock_install_build_snaps):
        project = self.make_snapcraft_project(
            textwrap.dedent(
                """\
                parts:
                  part1:
                    plugin: nil
                    build-snaps: [snap1, snap2]
                """
            )
        )

        lifecycle.execute(steps.PULL, project)

        mock_install_build_snaps.assert_called_once_with({"snap1", "snap2"})
github snapcore / snapcraft / tests / unit / pluginhandler / test_pluginhandler.py View on Github external
def test_pc_files_correctly_prefixed_when_installed(self):
        pc_file = os.path.join("usr", "lib", "pkgconfig", "granite.pc")
        install_path = os.path.join(self.parts_dir, "stage-pc", "install")
        stage_pc_install = os.path.join(install_path, pc_file)
        stage_pc_stage = os.path.join(self.stage_dir, pc_file)

        # Run build
        project_config = self.make_snapcraft_project()
        lifecycle.execute(steps.BUILD, project_config)

        # Simulate a .pc file was installed
        os.makedirs(os.path.dirname(stage_pc_install))
        with open(stage_pc_install, "w") as f:
            f.write("prefix={}/usr\n".format(install_path))
            f.write("exec_prefix=${prefix}\n")
            f.write("libdir=${prefix}/lib\n")
            f.write("includedir=${prefix}/include\n")
            f.write("\n")
            f.write("Name: granite\n")
            f.write("Description: elementary's Application Framework\n")
            f.write("Version: 0.4\n")
            f.write("Libs: -L${libdir} -lgranite\n")
            f.write("Cflags: -I${includedir}/granite\n")
            f.write("Requires: cairo gee-0.8 glib-2.0 gio-unix-2.0 gobject-2.0\n")
github snapcore / snapcraft / tests / unit / lifecycle / test_lifecycle.py View on Github external
provides=["test-virtual-package"],
            )
        )

        project_config = self.make_snapcraft_project(
            textwrap.dedent(
                """\
                parts:
                  test-part:
                    plugin: nil
                    build-packages: ['test-virtual-package']
                """
            )
        )

        lifecycle.execute(steps.PRIME, project_config)

        expected = textwrap.dedent(
            """\
            snapcraft-version: '3.0'
            snapcraft-started-at: '2019-05-07T19:25:53.939041Z'
            snapcraft-os-release-id: ubuntu
            snapcraft-os-release-version-id: '16.04'
            name: test
            base: core18
            version: '1.0'
            summary: test
            description: test
            confinement: strict
            grade: stable
            parts:
              test-part:
github snapcore / snapcraft / tests / unit / lifecycle / test_lifecycle.py View on Github external
("test-package2", "test-version2"),
        ]:
            self.fake_apt_cache.add_package(
                fixture_setup.FakeAptCachePackage(name, version, installed=True)
            )

        project_config = self.make_snapcraft_project(
            textwrap.dedent(
                """\
                parts:
                  test-part:
                    plugin: nil
                """
            )
        )
        lifecycle.execute(steps.PRIME, project_config)

        expected = textwrap.dedent(
            """\
            snapcraft-version: '3.0'
            snapcraft-started-at: '2019-05-07T19:25:53.939041Z'
            snapcraft-os-release-id: ubuntu
            snapcraft-os-release-version-id: '16.04'
            name: test
            base: core18
            version: '1.0'
            summary: test
            description: test
            confinement: strict
            grade: stable
            parts:
              test-part:
github snapcore / snapcraft / tests / unit / pluginhandler / test_pluginhandler.py View on Github external
def test_pc_files_correctly_prefixed(self):
        pc_file = os.path.join("usr", "lib", "pkgconfig", "granite.pc")
        stage_pc_install = os.path.join(self.parts_dir, "stage-pc", "install", pc_file)
        stage_pc_stage = os.path.join(self.stage_dir, pc_file)

        # Run build
        project_config = self.make_snapcraft_project()
        lifecycle.execute(steps.BUILD, project_config)

        # Simulate a .pc file was installed
        os.makedirs(os.path.dirname(stage_pc_install))
        with open(stage_pc_install, "w") as f:
            f.write("prefix=/usr\n")
            f.write("exec_prefix=${prefix}\n")
            f.write("libdir=${prefix}/lib\n")
            f.write("includedir=${prefix}/include\n")
            f.write("\n")
            f.write("Name: granite\n")
            f.write("Description: elementary's Application Framework\n")
            f.write("Version: 0.4\n")
            f.write("Libs: -L${libdir} -lgranite\n")
            f.write("Cflags: -I${includedir}/granite\n")
            f.write("Requires: cairo gee-0.8 glib-2.0 gio-unix-2.0 gobject-2.0\n")
github snapcore / snapcraft / tests / unit / lifecycle / test_lifecycle.py View on Github external
self.fake_apt_cache.add_package(
                fixture_setup.FakeAptCachePackage(name, version)
            )

        project_config = self.make_snapcraft_project(
            textwrap.dedent(
                """\
                build-packages: [test-package1=test-version1, test-package2]
                parts:
                  test-part:
                    plugin: nil
                """
            )
        )

        lifecycle.execute(steps.PRIME, project_config)

        expected = textwrap.dedent(
            """\
            snapcraft-version: '3.0'
            snapcraft-started-at: '2019-05-07T19:25:53.939041Z'
            snapcraft-os-release-id: ubuntu
            snapcraft-os-release-version-id: '16.04'
            name: test
            base: core18
            version: '1.0'
            summary: test
            description: test
            confinement: strict
            grade: stable
            build-packages:
            - test-package1=test-version1
github snapcore / snapcraft / snapcraft / cli / lifecycle.py View on Github external
) -> "Project":
    # Cleanup any previous errors.
    _clean_provider_error()

    build_provider = get_build_provider(**kwargs)
    is_managed_host = build_provider == "managed-host"

    project = get_project(is_managed_host=is_managed_host, **kwargs)
    build_provider_flags = get_build_provider_flags(build_provider, **kwargs)

    conduct_project_sanity_check(project)

    if build_provider in ["host", "managed-host"]:
        apply_host_provider_flags(build_provider_flags)
        project_config = project_loader.load_config(project)
        lifecycle.execute(step, project_config, parts)
        if pack_project:
            _pack(project.prime_dir, output=output)
    else:
        build_provider_class = build_providers.get_provider_for(build_provider)
        try:
            build_provider_class.ensure_provider()
        except build_providers.errors.ProviderNotFound as provider_error:
            if provider_error.prompt_installable:
                if echo.is_tty_connected() and echo.confirm(
                    "Support for {!r} needs to be set up. "
                    "Would you like to do that it now?".format(provider_error.provider)
                ):
                    build_provider_class.setup_provider(echoer=echo)
                else:
                    raise provider_error
            else:
github snapcore / snapcraft / snapcraft / main.py View on Github external
def run(args, project_options):  # noqa
    lifecycle_command = _get_lifecycle_command(args)
    argless_command = _get_command_from_arg(args)
    if lifecycle_command:
        if _is_containerbuild():
            lifecycle.containerbuild(lifecycle_command, project_options,
                                     args[''])
        else:
            lifecycle.execute(
                lifecycle_command, project_options, args[''])
    elif argless_command:
        argless_command()
    elif args['clean']:
        if _is_containerbuild():
            step = args['--step'] or 'pull'
            lifecycle.containerbuild('clean', project_options,
                                     args=['--step', step] + args[''])
        else:
            _run_clean(args, project_options)
    elif args['cleanbuild']:
        lifecycle.cleanbuild(project_options, remote=args['--remote']),
    elif _is_store_command(args):
        _run_store_command(args)
    elif args['tour']:
        _scaffold_examples(args[''] or _SNAPCRAFT_TOUR_DIR)