Exemplo n.º 1
0
async def check_default_tools(
    console: Console,
    real_opts: _Options,
) -> CheckDefaultTools:
    # The real options know about all the registered tools.
    for scope, si in real_opts.options.known_scope_to_info.items():
        if si.subsystem_cls and issubclass(si.subsystem_cls, ExternalTool):
            tool_cls = si.subsystem_cls
            console.print_stdout(f"Checking {console.cyan(tool_cls.name)}:")
            for known_version in tool_cls.default_known_versions:
                ver, plat_val, sha256, length = tool_cls.split_known_version_str(
                    known_version)
                # Note that we don't want to use the real option values here - we want to
                # verify that the *defaults* aren't broken. However the get_request_for() method
                # requires an instance (since it can consult option values, including custom
                # options for specific tools, that we don't know about), so we construct a
                # default one, but we force the --version to the one we're checking (which will
                # typically be the same as the default version, but doesn't have to be, if the
                # tool provides default_known_versions for versions other than default_version).
                args = ("./pants", f"--{scope}-version={ver}")
                blank_opts = await Get(
                    _Options,
                    SessionValues({
                        OptionsBootstrapper:
                        OptionsBootstrapper(tuple(), ("./pants", ), args,
                                            Config(tuple()), CliAlias())
                    }),
                )
                instance = tool_cls(blank_opts.options.for_scope(scope))
                req = instance.get_request_for(plat_val, sha256, length)
                console.write_stdout(f"  version {ver} for {plat_val}... ")
                # TODO: We'd like to run all the requests concurrently, but since we can't catch
                #  engine exceptions, we wouldn't have an easy way to output which one failed.
                await Get(DownloadedExternalTool, ExternalToolRequest, req)
                console.print_stdout(console.sigil_succeeded())
    return CheckDefaultTools(exit_code=0)