How to use the snapcraft.BasePlugin 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_update_build_organizes_with_overwrite(self, mock_organize):
        class TestPlugin(snapcraft.BasePlugin):
            def __init__(self, *args, **kwargs):
                super().__init__(*args, **kwargs)
                self.out_of_source_build = True

        self.useFixture(fixture_setup.FakePlugin("test-plugin", TestPlugin))

        handler = self.load_part("test-part", plugin_name="test-plugin")
        handler.makedirs()
        handler.update_build()
        mock_organize.assert_called_once_with(
            "test-part", {}, handler.plugin.installdir, True
        )
github snapcore / snapcraft / tests / integration / snaps / local-plugin-pull-properties / parts / plugins / x_local_plugin.py View on Github external
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see .

from snapcraft import BasePlugin


class LocalPlugin(BasePlugin):
    @classmethod
    def schema(cls):
        schema = super().schema()

        schema["properties"]["foo"] = {"type": "string"}

        return schema

    @classmethod
    def get_pull_properties(cls):
        return ["foo", "stage-packages"]
github snapcore / snapcraft / tests / unit / plugins / test_base.py View on Github external
def test_run_output_specifying_a_cwd(self, mock_run):
        plugin = snapcraft.BasePlugin("test/part", options=None)
        plugin.run_output(["ls"], cwd=plugin.sourcedir)

        mock_run.assert_called_once_with(["ls"], cwd=plugin.sourcedir)
github snapcore / snapcraft / snapcraft / plugins / go14_project.py View on Github external
# it under the terms of the GNU 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see .

import os
import snapcraft


class Go14ProjectPlugin(snapcraft.BasePlugin):
    def __init__(self, name, config, options):
        super().__init__(name, config, options)
        if self.options.source.startswith("lp:"):
            self.fullname = self.options.source.split(":~")[1]
        else:
            self.fullname = self.options.source.split("://")[1]

    def pull(self):
        return self.run(['go', 'get', '-t', self.fullname])

    def build(self):
        if not self.run(['go', 'build', self.fullname]):
            return False
        if not self.run(['go', 'install', self.fullname]):
            return False
        return self.run(['cp', '-a', os.path.join(self.builddir, 'bin'), self.installdir])
github snapcore / snapcraft / snapcraft / plugins / ubuntu.py View on Github external
import itertools
import logging
import os
import subprocess
import sys

import apt

import snapcraft.common


logger = logging.getLogger(__name__)


class UbuntuPlugin(snapcraft.BasePlugin):

    def __init__(self, name, options):
        super().__init__(name, options)
        self.downloadable_packages = []
        self.included_packages = []
        if options.packages:
            self.included_packages.extend(options.packages)
        else:
            # User didn't specify a package, use the part name
            if name == 'ubuntu':
                logger.error('Part %s needs either a package option or a name', name)
                sys.exit(1)
            self.included_packages.append(name)

        self.recommends = getattr(options, 'recommends', None)
github snapcore / snapcraft / snapcraft / plugins / go.py View on Github external
existing_cgo_ldflags = os.getenv("CGO_LDFLAGS")
    if existing_cgo_ldflags:
        cgo_ldflags.append(existing_cgo_ldflags)

    flags = common.combine_paths(library_paths, "-L", " ")
    if flags:
        cgo_ldflags.append(flags)

    ldflags = os.getenv("LDFLAGS")
    if ldflags:
        cgo_ldflags.append(ldflags)

    return " ".join(cgo_ldflags)


class GoPlugin(snapcraft.BasePlugin):
    @classmethod
    def schema(cls) -> Dict[str, Any]:
        schema = super().schema()
        schema["properties"]["go-channel"] = {
            "type": "string",
            "default": "latest/stable",
        }
        schema["properties"]["go-packages"] = {
            "type": "array",
            "minitems": 1,
            "uniqueItems": True,
            "items": {"type": "string"},
            "default": [],
        }
        schema["properties"]["go-importpath"] = {"type": "string", "default": ""}
        schema["properties"]["go-buildtags"] = {
github snapcore / snapcraft / snapcraft / plugins / make.py View on Github external
- make-parameters:
      (list of strings)
      Pass the given parameters to the make command.

    - make-install-var:
      (string; default: DESTDIR)
      Use this variable to redirect the installation into the snap.
"""

import os
import snapcraft
import snapcraft.common
from snapcraft.internal import errors


class MakePlugin(snapcraft.BasePlugin):
    @classmethod
    def schema(cls):
        schema = super().schema()
        schema["properties"]["makefile"] = {"type": "string"}
        schema["properties"]["make-parameters"] = {
            "type": "array",
            "minitems": 1,
            "uniqueItems": True,
            "items": {"type": "string"},
            "default": [],
        }
        schema["properties"]["make-install-var"] = {
            "type": "string",
            "default": "DESTDIR",
        }
        schema["properties"]["artifacts"] = {
github snapcore / snapcraft / snapcraft / plugins / dump.py View on Github external
import snapcraft
from snapcraft.internal import errors


class DumpInvalidSymlinkError(errors.SnapcraftError):
    fmt = (
        "Failed to copy {path!r}: it's a symlink pointing outside the snap.\n"
        "Fix it to be valid when snapped and try again."
    )

    def __init__(self, path):
        super().__init__(path=path)


class DumpPlugin(snapcraft.BasePlugin):
    @classmethod
    def schema(cls):
        schema = super().schema()
        schema["required"] = ["source"]
        return schema

    def enable_cross_compilation(self):
        pass

    def build(self):
        super().build()
        snapcraft.file_utils.link_or_copy_tree(
            self.builddir,
            self.installdir,
            copy_function=lambda src, dst: _link_or_copy(src, dst, self.installdir),
        )
github snapcore / snapcraft / snapcraft / plugins / colcon.py View on Github external
super().__init__(path=path)


class ColconPluginBaseError(errors.PluginBaseError):
    fmt = (
        "The colcon plugin (used by part {part_name!r}) does not support using base "
        "{base!r} with rosdistro {rosdistro!r}."
    )

    def __init__(self, part_name, base, rosdistro):
        super(errors.PluginBaseError, self).__init__(
            part_name=part_name, base=base, rosdistro=rosdistro
        )


class ColconPlugin(snapcraft.BasePlugin):
    @classmethod
    def schema(cls):
        schema = super().schema()

        schema["properties"]["colcon-rosdistro"] = {
            "type": "string",
            "default": "crystal",
            "enum": list(_ROSDISTRO_TO_BASE_MAP.keys()),
        }

        schema["properties"]["colcon-packages"] = {
            "type": "array",
            "minitems": 1,
            "uniqueItems": True,
            "items": {"type": "string"},
        }
github snapcore / snapcraft / snapcraft / plugins / rust.py View on Github external
import os
from contextlib import suppress
from typing import List, Optional

import toml

import snapcraft
from snapcraft import sources
from snapcraft import shell_utils
from snapcraft.internal import errors

_RUSTUP = "https://sh.rustup.rs/"
logger = logging.getLogger(__name__)


class RustPlugin(snapcraft.BasePlugin):
    @classmethod
    def schema(cls):
        schema = super().schema()
        schema["properties"]["rust-channel"] = {
            "type": "string",
            "enum": ["stable", "beta", "nightly"],
        }
        schema["properties"]["rust-revision"] = {"type": "string"}
        schema["properties"]["rust-features"] = {
            "type": "array",
            "minitems": 1,
            "uniqueItems": True,
            "items": {"type": "string"},
            "default": [],
        }
        schema["required"] = ["source"]