How to use the snapcraft.yaml_utils.load 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 / integration / general / test_parts.py View on Github external
def test_curl_exists_and_properly_defined(self):
        """Curl is used in most of the demos so we test for its existence."""
        self.run_snapcraft("update")
        output = self.run_snapcraft(["define", "curl"])

        expected_prefix = (
            "Maintainer: 'Sergio Schvezov '\n"
            "Description: A tool and a library (usable from many languages) "
            "for client side URL transfers, supporting FTP, FTPS, HTTP, "
            "HTTPS, TELNET, DICT, FILE and LDAP.\n\n"
        )
        self.assertThat(output, Contains(expected_prefix))
        idx = output.index(expected_prefix) + len(expected_prefix)
        part = yaml_utils.load(output[idx:])
        expected_part = {
            "curl": {
                "plugin": "autotools",
                "source": "http://curl.haxx.se/download/curl-7.44.0.tar.bz2",
                "source-type": "tar",
                "configflags": [
                    "--enable-static",
                    "--enable-shared",
                    "--disable-manual",
                ],
                "snap": [
                    "-bin",
                    "-lib/*.a",
                    "-lib/pkgconfig",
                    "-lib/*.la",
                    "-include",
github snapcore / snapcraft / tests / unit / test_parser.py View on Github external
def test_ordereddict_yaml(self):
        from collections import OrderedDict

        data = OrderedDict()

        data["name"] = "test"
        data["description"] = "description"

        output = yaml_utils.dump(data)

        self.assertTrue(isinstance(yaml_utils.load(output), OrderedDict))
github snapcore / snapcraft / tests / unit / states / test_prime.py View on Github external
def test_yaml_conversion(self, init_spy):
        state_string = yaml_utils.dump(self.state)

        # Verify that the dumped tag was correct
        self.assertThat(state_string.splitlines()[0], Equals("!PrimeState"))

        # Now verify the conversion
        state_from_yaml = yaml_utils.load(state_string)
        self.assertThat(state_from_yaml, Equals(self.state))

        # Verify that init was not called
        init_spy.assert_not_called()
github snapcore / snapcraft / snapcraft / cli / assertions.py View on Github external
def _edit_developers(developers: List[Dict[str, str]]) -> List[Dict[str, str]]:
    """Spawn an editor to modify the snap-developer assertion for a snap."""
    editor_cmd = os.getenv("EDITOR", "vi")

    developer_wrapper = {"developers": developers}

    with tempfile.NamedTemporaryFile() as ft:
        ft.close()
        with open(ft.name, "w") as fw:
            print(_COLLABORATION_HEADER, file=fw)
            yaml_utils.dump(developer_wrapper, stream=fw)
        subprocess.check_call([editor_cmd, ft.name])
        with open(ft.name, "r") as fr:
            developers = yaml_utils.load(fr).get("developers")
    return developers
github snapcore / snapcraft / snapcraft / internal / lifecycle / _packer.py View on Github external
def _snap_data_from_dir(directory):
    with open(os.path.join(directory, "meta", "snap.yaml")) as f:
        snap = yaml_utils.load(f)

    return {
        "name": snap["name"],
        "version": snap["version"],
        "arch": snap.get("architectures", []),
        "type": snap.get("type", ""),
        "license": snap.get("license"),
    }
github snapcore / snapcraft / snapcraft / internal / meta / snap.py View on Github external
def from_file(cls, snap_yaml_path: str) -> "Snap":
        with open(snap_yaml_path, "r") as f:
            snap_dict = yaml_utils.load(f)
            return cls.from_dict(snap_dict=snap_dict)
github snapcore / snapcraft / snapcraft / internal / build_providers / _base_provider.py View on Github external
def _load_info(self) -> Dict[str, Any]:
        filepath = os.path.join(self.provider_project_dir, "project-info.yaml")
        if not os.path.exists(filepath):
            return dict()

        with open(filepath) as info_file:
            return yaml_utils.load(info_file)
github snapcore / snapcraft / snapcraft / internal / remote_parts.py View on Github external
def __init__(self):
        super().__init__()

        if not os.path.exists(self.parts_yaml):
            update()

        with open(self.parts_yaml) as parts_file:
            self._parts = yaml_utils.load(parts_file)