Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_set_grade_without_fifo(self):
raised = self.assertRaises(
errors.SnapcraftEnvironmentError,
self.run_command,
["set-grade", "test-grade"],
)
self.assertThat(
str(raised),
Contains(
"environment variable must be defined. Note that this utility is "
"only designed for use within a snapcraft.yaml"
def test_cross_compiler_prefix_missing(self):
options = snapcraft.ProjectOptions(target_deb_arch="x86_64")
with testtools.ExpectedException(
SnapcraftEnvironmentError,
"Cross compilation not supported for target arch 'x86_64'",
):
options.cross_compiler_prefix
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):
os.mkdir(os.path.dirname(snapcraft_yaml_path))
with open(snapcraft_yaml_path, mode="w") as f:
f.write(text)
return snapcraft_yaml_path
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(
self.project.deb_arch
)
)
return rust_target.format("unknown-linux", "gnu")
"""Returns the version of the linker from linker_file.
linker_file must be of the format ld-.so
: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 = re.search(r"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 "
"/ld-..so. {!r} does not match that format. "
"Ensure you are targeting an appropriate base".format(linker_file)
)
linker_version = m.group("linker_version")
return linker_version
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])
def _create_bins(package_json, directory):
bin_entry = package_json.get("bin")
if not bin_entry:
return
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}
else:
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)):
continue
source = os.path.join("..", bin_path)
os.symlink(source, target)
# Make it executable
os.chmod(os.path.realpath(target), 0o755)
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 https://snapcraft.io/snapcraft 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)