How to use snapcraft - 10 common examples

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 / snaps_tests / demos_tests / test_git.py View on Github external
def test_git(self):
        if snapcraft.ProjectOptions().deb_arch == 'armhf':
            self.skipTest("Snaps can't yet be installed in a lxc container.")

        # Building classic snaps require the core snap to be installed
        self.install_store_snap('core')

        self.build_snap(self.snap_content_dir)
        # TODO reenable git once snap-confine and snapd bits are in place
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 / test_os_release.py View on Github external
def test_no_name(self):
        release = os_release.OsRelease(
            os_release_file=self._write_os_release(
                dedent(
                    """\
                ID=arch
                PRETTY_NAME="Arch Linux"
                ID_LIKE=archlinux
                VERSION_ID="foo"
                VERSION_CODENAME="bar"
            """
                )
            )
        )

        self.assertRaises(errors.OsReleaseNameError, release.name)
github snapcore / snapcraft / tests / unit / lifecycle / test_lifecycle.py View on Github external
def test_prime_with_invalid_image_info_raises_exception(self):
        self.useFixture(fixtures.EnvironmentVariable("SNAPCRAFT_BUILD_INFO", "1"))
        self.useFixture(
            fixtures.EnvironmentVariable("SNAPCRAFT_IMAGE_INFO", "not-json")
        )
        project_config = self.make_snapcraft_project(
            textwrap.dedent(
                """\
                parts:
                  test-part:
                    plugin: nil
                """
            )
        )
        raised = self.assertRaises(
            errors.InvalidContainerImageInfoError,
            lifecycle.execute,
            steps.PRIME,
            project_config,
        )
        self.assertThat(raised.image_info, Equals("not-json"))
github snapcore / snapcraft / tests / unit / plugins / test_make.py View on Github external
def test_unsupported_base(self):
        project = snapcraft.project.Project(
            snapcraft_yaml_file_path=self.make_snapcraft_yaml(
                textwrap.dedent(
                    """\
                    name: make-snap
                    base: unsupported-base
                    """
                )
            )
        )

        raised = self.assertRaises(
            errors.PluginBaseError, make.MakePlugin, "test-part", self.options, project
        )

        self.assertThat(raised.part_name, Equals("test-part"))
        self.assertThat(raised.base, Equals("unsupported-base"))
github snapcore / snapcraft / tests / unit / plugins / test_meson.py View on Github external
def test_unsupported_base_raises(self):
        self.assertRaises(
            errors.PluginBaseError,
            meson.MesonPlugin,
            "test-part",
            self.options,
            self.project,
        )
github snapcore / snapcraft / tests / unit / pluginhandler / test_plugin_loader.py View on Github external
def test_known_module_but_unknown_plugin_must_raise_exception(self):
        fake_logger = fixtures.FakeLogger(level=logging.ERROR)
        self.useFixture(fake_logger)

        path = copy.copy(sys.path)

        # "_ros" is a valid module within the plugin path, but contains no
        # plugins.
        raised = self.assertRaises(
            errors.PluginError, self.load_part, "fake-part", "_ros"
        )

        self.assertThat(raised.message, Equals("no plugin found in module '_ros'"))

        # Make sure that nothing was added to sys.path.
        self.assertThat(path, Equals(sys.path))
github snapcore / snapcraft / tests / fixture_setup / _unittests.py View on Github external
def setUp(self):
        super().setUp()

        patcher = mock.patch("snapcraft.project.Project")
        patcher.start()
        self.addCleanup(patcher.stop)

        # Special handling is required as ProjectOptions attributes are
        # handled with the @property decorator.
        project_options_t = type(snapcraft.project.Project.return_value)
        for key in self._kwargs:
            setattr(project_options_t, key, self._kwargs[key])
github snapcore / snapcraft / tests / unit / lifecycle / __init__.py View on Github external
base: core18
            version: "1.0"
            summary: test
            description: test
            confinement: strict
            grade: stable
            {type}

            {parts}
            """
        )

        self.snapcraft_yaml_file_path = self.make_snapcraft_yaml(
            yaml.format(parts=parts, type=snap_type)
        )
        project = snapcraft.project.Project(
            snapcraft_yaml_file_path=self.snapcraft_yaml_file_path
        )
        return project_loader.load_config(project)
github snapcore / snapcraft / tests / unit / remote_build / test_launchpad.py View on Github external
def _make_snapcraft_project(self):
        yaml = textwrap.dedent(
            """\
            name: test
            base: core18
            version: "1.0"
            summary: test
            description: test
            confinement: strict
            grade: stable
            """
        )
        snapcraft_yaml_file_path = self.make_snapcraft_yaml(yaml)
        project = snapcraft.project.Project(
            snapcraft_yaml_file_path=snapcraft_yaml_file_path
        )
        return project