Exemplo n.º 1
0
    def run(self, parsed_args):
        extension_presentation: Dict[str, ExtensionModel] = {}

        # New extensions.
        for extension_name in extensions.registry.get_extension_names():
            extension_class = extensions.registry.get_extension_class(
                extension_name)
            extension_bases = list(extension_class.get_supported_bases())
            extension_presentation[extension_name] = ExtensionModel(
                name=extension_name, bases=extension_bases)

        # Extensions from snapcraft_legacy.
        for extension_name in supported_extension_names():
            extension_class = find_extension(extension_name)
            extension_name = extension_name.replace("_", "-")
            extension_bases = list(extension_class.get_supported_bases())
            if extension_name in extension_presentation:
                extension_presentation[extension_name].bases += extension_bases
            else:
                extension_presentation[extension_name] = ExtensionModel(
                    name=extension_name, bases=extension_bases)

        printable_extensions = sorted(
            [v.marshal() for v in extension_presentation.values()],
            key=lambda d: d["Extension name"],
        )
        emit.message(tabulate.tabulate(printable_extensions, headers="keys"))
Exemplo n.º 2
0
 def test_all_extension_docs(self):
     for extension_name in supported_extension_names():
         try:
             self.run_command(["extension", extension_name])
         except Exception:
             self.fail(
                 "The {!r} extension appears to be missing documentation".
                 format(extension_name))
Exemplo n.º 3
0
class ExtensionCombinationTest(ProjectLoaderBaseTest):
    scenarios = multiply_scenarios(*(
        [[
            (
                "{} extension".format(extension_name),
                {
                    "extension_{}".format(extension_name): extension_name
                },
            ),
            (
                "no {} extension".format(extension_name),
                {
                    "extension_{}".format(extension_name): None
                },
            ),
        ] for extension_name in supported_extension_names()] or
        [[]]  # This guard can be removed once at least one extension is added
    ))

    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}")
Exemplo n.º 4
0
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.replace("_", "-")
        extension_info["Supported bases"] = ", ".join(
            sorted(extension.get_supported_bases()))
        extensions.append(extension_info)

    click.echo(tabulate.tabulate(extensions, headers="keys"))