def check_cli_version()

in bonsaicli2/bonsai_cli/utils.py [0:0]


    def check_cli_version(self, wait: bool, print_up_to_date: bool = True) -> None:
        """
        Compares local cli version with the one on PyPi.

        If latest version is not yet known and wait is False, this function
        blocks for a brief period of time to allow it to complete. If wait is
        instead True, this function blocks indefinitely for a response.
        """
        pypi_version, err = self._get_version_result(wait)

        # If we lack a latest version, only continue to print what we do know
        # when waitiing was a requirement. When it wasn't, this appears as
        # unexpected error output spam for an otherwise-innocent command.
        if pypi_version is None and not wait:
            return

        user_cli_version = __version__

        if not pypi_version:
            click_echo(
                "You are using bonsai-cli version " + user_cli_version, fg="yellow"
            )
            click_echo(
                "Unable to connect to PyPi and determine if CLI is up to date.",
                fg="red",
            )
            if isinstance(err, requests.exceptions.SSLError):
                click_echo(
                    "The following SSL error occurred while attempting to obtain"
                    " the version information from PyPi. \n\n{}\n\n".format(err)
                    + "SSL errors are usually a result of an out of date version of"
                    " OpenSSL and/or certificates that may need to be updated."
                    " We recommend updating your python install to a more"
                    " recent version. If this is not possible, 'pip install"
                    " requests[security]' may fix the problem.",
                    fg="red",
                )
            elif err:
                click_echo(
                    "The following error occurred while attempting to obtain the"
                    " version information from PyPi.\n\n{}\n".format(err),
                    fg="red",
                )
        elif user_cli_version != pypi_version:
            click_echo(
                "You are using bonsai-cli version " + user_cli_version, fg="yellow"
            )
            click_echo(
                "Bonsai update available. The most recent version is "
                + pypi_version
                + ".",
                fg="yellow",
            )
            click_echo(
                "Upgrade via pip using 'pip install --upgrade bonsai-cli'", fg="yellow"
            )
        elif print_up_to_date:
            click_echo(
                "You are using bonsai-cli version "
                + user_cli_version
                + ", Everything is up to date.",
                fg="green",
            )