How to use the snapcraft.internal.errors.SnapcraftEnvironmentError 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 / commands / snapcraftctl / View on Github external
def test_set_grade_without_fifo(self):
        raised = self.assertRaises(
            ["set-grade", "test-grade"],

                "environment variable must be defined. Note that this utility is "
                "only designed for use within a snapcraft.yaml"
github snapcore / snapcraft / tests / unit / View on Github external
def test_cross_compiler_prefix_missing(self):
        options = snapcraft.ProjectOptions(target_deb_arch="x86_64")

        with testtools.ExpectedException(
            "Cross compilation not supported for target arch 'x86_64'",
github snapcore / snapcraft / snapcraft / internal / lifecycle / View on Github external
def init():
    """Initialize a snapcraft project."""
    snapcraft_yaml_path = os.path.join("snap", "snapcraft.yaml")

    if os.path.exists(snapcraft_yaml_path):
        raise errors.SnapcraftEnvironmentError(
            "{} already exists!".format(snapcraft_yaml_path)
    elif os.path.exists("snapcraft.yaml"):
        raise errors.SnapcraftEnvironmentError("snapcraft.yaml already exists!")
    elif os.path.exists(".snapcraft.yaml"):
        raise errors.SnapcraftEnvironmentError(".snapcraft.yaml already exists!")
    text = _TEMPLATE_YAML
    with contextlib.suppress(FileExistsError):
    with open(snapcraft_yaml_path, mode="w") as f:

    return snapcraft_yaml_path
github snapcore / snapcraft / snapcraft / plugins / View on Github external
def _get_target(self) -> str:
        # Cf. rustc --print target-list
        targets = {
            "armhf": "armv7-{}-{}eabihf",
            "arm64": "aarch64-{}-{}",
            "i386": "i686-{}-{}",
            "amd64": "x86_64-{}-{}",
            "ppc64el": "powerpc64le-{}-{}",
            "s390x": "s390x-{}-{}",
        rust_target = targets.get(self.project.deb_arch)
        if not rust_target:
            raise errors.SnapcraftEnvironmentError(
                "{!r} is not supported as a target architecture ".format(
        return rust_target.format("unknown-linux", "gnu")
github snapcore / snapcraft / snapcraft / View on Github external
"""Returns the version of the linker from linker_file.

    linker_file must be of the format

    :param str linker_file: a valid file path or basename representing
                            the linker from libc6 or related.
    :returns: the version extracted from the linker file.
    :rtype: string
    :raises snapcraft.internal.errors.SnapcraftEnvironmentError:
       if linker_file is not of the expected format.
    m ="ld-(?P[\d.]+).so$", linker_file)
    if not m:
        # This is a programmatic error, we don't want to be friendly
        # about this.
        raise SnapcraftEnvironmentError(
            "The format for the linker should be of the of the form "
            "/ {!r} does not match that format. "
            "Ensure you are targeting an appropriate base".format(linker_file)
    linker_version ="linker_version")

    return linker_version
github gohugoio / hugo / snap / plugins / View on Github external
def _get_nodejs_base(node_engine, machine):
    if machine not in _NODEJS_ARCHES:
        raise errors.SnapcraftEnvironmentError(
            "architecture not supported ({})".format(machine)
    return _NODEJS_BASE.format(version=node_engine, arch=_NODEJS_ARCHES[machine])
github snapcore / snapcraft / snapcraft / plugins / View on Github external
def _create_bins(package_json, directory):
    bin_entry = package_json.get("bin")
    if not bin_entry:

    bin_dir = os.path.join(directory, "bin")
    os.makedirs(bin_dir, exist_ok=True)

    if type(bin_entry) == dict:
        binaries = bin_entry
    elif type(bin_entry) == str:
        # Support for scoped names of the form of @org/name
        name = package_json["name"]
        binaries = {name[name.find("/") + 1 :]: bin_entry}
        raise errors.SnapcraftEnvironmentError(
            "The plugin is not prepared to handle bin entries of "
            "type {!r}".format(type(bin_entry))

    for bin_name, bin_path in binaries.items():
        target = os.path.join(bin_dir, bin_name)
        # The binary might be already created from upstream sources.
        if os.path.exists(os.path.join(target)):
        source = os.path.join("..", bin_path)
        os.symlink(source, target)
        # Make it executable
        os.chmod(os.path.realpath(target), 0o755)
github snapcore / snapcraft / snapcraft / cli / View on Github external
def run_legacy_snapcraft(argv=sys.argv[1:]) -> None:
    if not common.is_snap():
        raise errors.SnapcraftEnvironmentError(
            "Legacy mode not supported in this installation. "
            "Install snapcraft from and try again."

    legacy_python = os.path.join(
        common.get_legacy_snapcraft_dir(), "usr", "bin", "python3"
    legacy_snapcraft = os.path.join(
        common.get_legacy_snapcraft_dir(), "bin", "snapcraft"

    cmd = [legacy_python, legacy_snapcraft] + argv
    logging.debug("Running legacy snapcraft with: {}".format(cmd))
    os.execv(legacy_python, cmd)