How to use the snapcraft.ProjectOptions 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 / 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 / project_loader / grammar / test_on_statement.py View on Github external
def test_on_statement_invalid_grammar(self):
        with testtools.ExpectedException(
            grammar.errors.OnStatementSyntaxError, self.expected_exception
        ):
            processor = grammar.GrammarProcessor(
                None, snapcraft.ProjectOptions(), self.checker
            )
            statement = on.OnStatement(on=self.on, body=self.body, processor=processor)

            for else_body in self.else_bodies:
                statement.add_else(else_body)

            statement.process()
github snapcore / snapcraft / tests / unit / plugins / test_copy.py View on Github external
def setUp(self):
        super().setUp()
        self.mock_options = Mock()
        self.mock_options.source = "."
        self.mock_options.source_subdir = None
        self.mock_options.files = {}
        # setup the expected target dir in our tempdir
        self.dst_prefix = "parts/copy/install/"
        os.makedirs(self.dst_prefix)
        self.project_options = snapcraft.ProjectOptions()
github snapcore / snapcraft / tests / unit / plugins / test_ament.py View on Github external
def setUp(self):
        super().setUp()

        class props:
            version = "release-beta3"

        self.properties = props()
        self.project = snapcraft.ProjectOptions()

        patcher = mock.patch("snapcraft.plugins._ros.ros2.Bootstrapper")
        self.bootstrapper_mock = patcher.start()
        self.addCleanup(patcher.stop)
github snapcore / snapcraft / tests / unit / store / test_agent.py View on Github external
def test_user_agent(self):
        arch = ProjectOptions().deb_arch
        expected_pre = "snapcraft/{} ".format(snapcraft_version)
        expected_post = " {} ({})".format(
            "/".join(platform.dist()[0:2]), arch  # i.e. Ubuntu/16.04
        )
        actual = storeapi._agent.get_user_agent()
        self.assertTrue(actual.startswith(expected_pre))
        self.assertTrue(actual.endswith(expected_post))
github snapcore / snapcraft / tests / unit / plugins / test_tar_content.py View on Github external
def setUp(self):
        super().setUp()

        self.project_options = snapcraft.ProjectOptions()

        # setup the expected target dir in our tempdir
        part_dir = os.path.join(self.parts_dir, "tar_content")
        self.build_prefix = os.path.join(part_dir, "build")
        os.makedirs(self.build_prefix)
        self.install_prefix = os.path.join(part_dir, "install")
        os.makedirs(self.install_prefix)
github snapcore / snapcraft / tests / unit / plugins / ros / test_wstool.py View on Github external
def setUp(self):
        super().setUp()
        self.project = snapcraft.ProjectOptions()
        self.wstool = wstool.Wstool(
            "package_path", "wstool_path", "sources", ["keyring"], self.project
        )

        patcher = mock.patch("snapcraft.repo.Ubuntu")
        self.ubuntu_mock = patcher.start()
        self.addCleanup(patcher.stop)

        patcher = mock.patch("subprocess.check_output")
        self.check_output_mock = patcher.start()
        self.addCleanup(patcher.stop)
github snapcore / snapcraft / tests / unit / test_options.py View on Github external
def test_cross_compiler_prefix_empty(
        self, mock_platform_machine, mock_platform_architecture
    ):
        mock_platform_machine.return_value = "x86_64"
        mock_platform_architecture.return_value = ("64bit", "ELF")
        options = snapcraft.ProjectOptions(target_deb_arch="i386")
        self.assertThat(options.cross_compiler_prefix, Equals(""))
github snapcore / snapcraft / snaps_tests / demos_tests / test_opencv.py View on Github external
def test_opencv(self):
        if snapcraft.ProjectOptions().deb_arch == "armhf":
            self.skipTest("The autopkgtest armhf runners can't install snaps")

        snap_path = self.build_snap(self.snap_content_dir)

        bin_path = os.path.join(os.path.dirname(snap_path), "prime", "bin", "example")
        self.assertThat(bin_path, FileExists())

        interpreter = subprocess.check_output(
            [self.patchelf_command, "--print-interpreter", bin_path]
        ).decode()
        expected_interpreter = r"^/snap/.*"
        self.assertThat(interpreter, MatchesRegex(expected_interpreter))

        arch_triplet = snapcraft.ProjectOptions().arch_triplet

        # test $ORIGIN in action
        rpath = subprocess.check_output(
            [self.patchelf_command, "--print-rpath", bin_path]
        ).decode()
        expected_rpath = "$ORIGIN/../usr/lib/{}:".format(arch_triplet)
        self.assertThat(rpath, Contains(expected_rpath))

        # test $ORIGIN applied
        ldd = subprocess.check_output(["ldd", bin_path]).decode()
        expected_opencv_path = "/prime/bin/../usr/lib/{}/libopencv_core".format(
            arch_triplet
        )
        self.assertThat(ldd, Contains(expected_opencv_path))

        self.install_snap(snap_path, "opencv-example", "1.0", classic=True)
github snapcore / snapcraft / snapcraft / storeapi / _store_client.py View on Github external
def download(
        self,
        snap_name,
        *,
        risk: str,
        download_path: str,
        track: str = None,
        arch: str = None,
        except_hash=""
    ):
        if arch is None:
            arch = snapcraft.ProjectOptions().deb_arch

        snap_info = self.cpi.get_info(snap_name)
        channel_mapping = snap_info.get_channel_mapping(
            risk=risk, track=track, arch=arch
        )
        if channel_mapping.download.sha3_384 == except_hash:
            return channel_mapping.download.sha3_384

        try:
            channel_mapping.download.verify(download_path)
        except errors.StoreDownloadError:
            self._download_snap(channel_mapping.download, download_path)

        channel_mapping.download.verify(download_path)
        return channel_mapping.download.sha3_384