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_no_name(self):
release = os_release.OsRelease(
os_release_file=self._write_os_release(
dedent(
"""\
ID=arch
PRETTY_NAME="Arch Linux"
ID_LIKE=archlinux
VERSION_ID="foo"
VERSION_CODENAME="bar"
"""
)
)
)
self.assertRaises(errors.OsReleaseNameError, release.name)
def test_prime_with_invalid_image_info_raises_exception(self):
self.useFixture(fixtures.EnvironmentVariable("SNAPCRAFT_BUILD_INFO", "1"))
self.useFixture(
fixtures.EnvironmentVariable("SNAPCRAFT_IMAGE_INFO", "not-json")
)
project_config = self.make_snapcraft_project(
textwrap.dedent(
"""\
parts:
test-part:
plugin: nil
"""
)
)
raised = self.assertRaises(
errors.InvalidContainerImageInfoError,
lifecycle.execute,
steps.PRIME,
project_config,
)
self.assertThat(raised.image_info, Equals("not-json"))
def test_unsupported_base(self):
project = snapcraft.project.Project(
snapcraft_yaml_file_path=self.make_snapcraft_yaml(
textwrap.dedent(
"""\
name: make-snap
base: unsupported-base
"""
)
)
)
raised = self.assertRaises(
errors.PluginBaseError, make.MakePlugin, "test-part", self.options, project
)
self.assertThat(raised.part_name, Equals("test-part"))
self.assertThat(raised.base, Equals("unsupported-base"))
def test_unsupported_base_raises(self):
self.assertRaises(
errors.PluginBaseError,
meson.MesonPlugin,
"test-part",
self.options,
self.project,
)
def test_known_module_but_unknown_plugin_must_raise_exception(self):
fake_logger = fixtures.FakeLogger(level=logging.ERROR)
self.useFixture(fake_logger)
path = copy.copy(sys.path)
# "_ros" is a valid module within the plugin path, but contains no
# plugins.
raised = self.assertRaises(
errors.PluginError, self.load_part, "fake-part", "_ros"
)
self.assertThat(raised.message, Equals("no plugin found in module '_ros'"))
# Make sure that nothing was added to sys.path.
self.assertThat(path, Equals(sys.path))
if os.path.exists(data_dir):
return data_dir
# Handle Options (b) & (c).
if topdir.startswith(sys.prefix):
data_dir = os.path.join(sys.prefix, "share", "snapcraft")
if os.path.exists(data_dir):
return data_dir
# Do our best to find something...
for data_dir in [topdir, sys.prefix, site.USER_BASE]:
data_dir = os.path.join(data_dir, "share", "snapcraft")
if os.path.exists(data_dir):
return data_dir
raise snapcraft.internal.errors.SnapcraftDataDirectoryMissingError()
# 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.internal import errors
class GrammarError(errors.SnapcraftError):
"""Base class for grammar-related errors."""
pass
class GrammarSyntaxError(GrammarError):
fmt = "Invalid grammar syntax: {message}"
def __init__(self, message):
super().__init__(message=message)
class OnStatementSyntaxError(GrammarSyntaxError):
def __init__(self, on_statement, *, message=None):
components = ["{!r} is not a valid 'on' clause".format(on_statement)]
Examples:
snapcraft clean
snapcraft clean my-part
"""
# This option is only valid in legacy.
if step:
option = "--step" if "--step" in ctx.obj["argv"] else "-s"
raise click.BadOptionUsage(option, "no such option: {}".format(option))
build_provider = get_build_provider(**kwargs)
build_provider_flags = get_build_provider_flags(build_provider, **kwargs)
is_managed_host = build_provider == "managed-host"
try:
project = get_project(is_managed_host=is_managed_host)
except errors.ProjectNotFoundError:
# Fresh environment, nothing to clean.
return
if unprime and not is_managed_host:
raise click.BadOptionUsage("--unprime", "no such option: --unprime")
if build_provider in ["host", "managed-host"]:
apply_host_provider_flags(build_provider_flags)
step = steps.PRIME if unprime else None
lifecycle.clean(project, parts, step)
else:
build_provider_class = build_providers.get_provider_for(build_provider)
if parts:
with build_provider_class(
project=project, echoer=echo, build_provider_flags=build_provider_flags
) as instance:
#
# 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 formatting_utils
from snapcraft.internal import errors
from typing import List
class SnapcraftSourceError(errors.SnapcraftError):
pass
class VCSError(SnapcraftSourceError):
fmt = "{message}"
class SnapcraftSourceNotFoundError(SnapcraftSourceError):
fmt = (
"Failed to pull source: {source!r}.\n"
"Please ensure the source path is correct and that it is accessible.\n"
"See `snapcraft help sources` for more information."
)
def __init__(self, source):
def _load_module(module_name, plugin_name, local_plugins_dir):
module = None
with contextlib.suppress(ImportError):
module = _load_local("x-{}".format(plugin_name), local_plugins_dir)
logger.info("Loaded local plugin for %s", plugin_name)
if not module:
with contextlib.suppress(ImportError):
module = importlib.import_module("snapcraft.plugins.{}".format(module_name))
if not module:
logger.info("Searching for local plugin for %s", plugin_name)
with contextlib.suppress(ImportError):
module = _load_local(module_name, local_plugins_dir)
if not module:
raise errors.PluginError("unknown plugin: {!r}".format(plugin_name))
return module