コード例 #1
0
def extension(name, **kwargs):
    """Show contents of extension."""
    from snapcraft.internal import project_loader

    dummy_data = lifecycle.get_init_data()
    extension_instance = project_loader.find_extension(name)(dummy_data)

    app_snippet = extension_instance.app_snippet
    part_snippet = extension_instance.part_snippet
    parts = extension_instance.parts

    intro = "The {} extension".format(name)
    if app_snippet:
        click.echo("{} adds the following to apps that use it:".format(intro))
        click.echo(
            textwrap.indent(
                yaml.safe_dump(app_snippet, default_flow_style=False), "    "))
        intro = "It"

    if part_snippet:
        click.echo("{} adds the following to all parts:".format(intro))
        click.echo(
            textwrap.indent(
                yaml.safe_dump(part_snippet, default_flow_style=False),
                "    "))
        intro = "It"

    if parts:
        click.echo("{} adds the following part definitions:".format(intro))
        click.echo(
            textwrap.indent(yaml.safe_dump(parts, default_flow_style=False),
                            "    "))
コード例 #2
0
def list_extensions(**kwargs):
    """List available extensions.

    This command has an alias of `extensions`.
    """
    from snapcraft.internal import project_loader

    extension_names = []
    for _, modname, _ in pkgutil.iter_modules(
            project_loader._extensions.__path__):
        # Only add non-private modules/packages to the extension list
        if not modname.startswith("_"):
            extension_names.append(modname)

    if not extension_names:
        click.echo("No extensions supported")
        return

    extensions = []
    for extension_name in sorted(extension_names):
        extension = project_loader.find_extension(extension_name)
        extension_info = collections.OrderedDict()
        extension_info["Extension name"] = extension_name
        extension_info["Supported bases"] = ", ".join(
            sorted(extension.supported_bases))
        extensions.append(extension_info)

    click.echo(tabulate.tabulate(extensions, headers="keys"))
コード例 #3
0
ファイル: extensions.py プロジェクト: ycheng/snapcraft
def extension(ctx, name, **kwargs):
    """Show contents of extension."""

    extension_cls = project_loader.find_extension(name)

    # Not using inspect.getdoc here since it'll fall back to the base class
    docstring = extension_cls.__doc__
    if not docstring:
        raise project_loader.errors.ExtensionMissingDocumentationError(name)

    formatter = ctx.make_formatter()
    formatter.write_text(inspect.cleandoc(docstring))
    click.echo(formatter.getvalue().rstrip("\n"))
コード例 #4
0
ファイル: extensions.py プロジェクト: ycliuhw/snapcraft
def list_extensions(**kwargs):
    """List available extensions.

    This command has an alias of `extensions`.
    """

    extension_names = project_loader.supported_extension_names()

    if not extension_names:
        click.echo("No extensions supported")
        return

    extensions = []
    for extension_name in sorted(extension_names):
        extension = project_loader.find_extension(extension_name)
        extension_info = collections.OrderedDict()
        extension_info["Extension name"] = extension_name
        extension_info["Supported bases"] = ", ".join(sorted(extension.supported_bases))
        extensions.append(extension_info)

    click.echo(tabulate.tabulate(extensions, headers="keys"))
コード例 #5
0
ファイル: test_extensions.py プロジェクト: nessita/snapcraft
    def test_extensions_all_combinations_validate(self):
        common_bases = set(["core18", "core20"])

        # Determine extension list given scenarios
        extension_names = list()
        for member_pair in inspect.getmembers(self):
            name = member_pair[0]
            if name.startswith("extension_"):
                value = getattr(self, name)
                if value:
                    extension_names.append(value)
                    ext = find_extension(value)
                    common_bases &= set(ext.get_supported_bases())

        # This shouldn't have any validation issues
        if common_bases:
            base = common_bases.pop()
            self.make_snapcraft_project(
                textwrap.dedent("""\
                    name: test
                    version: "1"
                    summary: test
                    description: test
                    base: {base}
                    grade: stable
                    confinement: strict

                    apps:
                        test-app:
                            command: test-command
                            adapter: full
                            extensions: {extensions}

                    parts:
                        part1:
                            plugin: nil
                    """).format(base=base, extensions=extension_names))
        else:
            self.skipTest(f"no common base: {extension_names!r}")