示例#1
0
    def test_should_check(self):
        with patch.object(CliConfigManager, 'reset') as patch_fct:
            result = CliConfigManager.should_check()

        assert patch_fct.call_count == 1
        assert result is True

        CliConfigManager.reset(current_version='0.0.5', min_version='0.0.4')
        with patch.object(CliConfigManager, 'reset') as patch_fct:
            result = CliConfigManager.should_check()

        assert patch_fct.call_count == 1
        assert result is False

        CliConfigManager.reset(check_count=4,
                               current_version='0.0.5',
                               min_version='0.0.4')
        with patch.object(CliConfigManager, 'reset') as patch_fct:
            result = CliConfigManager.should_check()

        assert patch_fct.call_count == 1
        assert result is True

        CliConfigManager.reset(current_version='0.0.2', min_version='0.0.4')
        with patch.object(CliConfigManager, 'reset') as patch_fct:
            result = CliConfigManager.should_check()

        assert patch_fct.call_count == 1
        assert result is True
示例#2
0
def check_cli_version():
    """Check if the current cli version satisfies the server requirements"""
    if not CliConfigManager.should_check():
        return

    server_version = get_server_version()
    current_version = get_current_version()
    CliConfigManager.reset(current_version=current_version,
                           min_version=server_version.min_version)

    if LooseVersion(current_version) < LooseVersion(
            server_version.min_version):
        click.echo(
            """Your version of CLI ({}) is no longer compatible with server."""
            .format(current_version))
        if click.confirm("Do you want to upgrade to "
                         "version {} now?".format(
                             server_version.latest_version)):
            pip_upgrade()
            sys.exit(0)
        else:
            clint.textui.puts("Your can manually run:")
            with clint.textui.indent(4):
                clint.textui.puts("pip install -U polyaxon-cli")
            clint.textui.puts("to upgrade to the latest version `{}`".format(
                server_version.latest_version))

            sys.exit(0)
    elif LooseVersion(current_version) < LooseVersion(
            server_version.latest_version):
        clint.textui.puts(
            "New version of CLI ({}) is now available. To upgrade run:".format(
                server_version.latest_version))
        with clint.textui.indent(4):
            clint.textui.puts("pip install -U polyaxon-cli")
示例#3
0
def check_cli_version():
    """Check if the current cli version satisfies the server requirements"""
    if not CliConfigManager.should_check():
        return

    from distutils.version import LooseVersion  # pylint:disable=import-error

    server_version = get_server_version()
    current_version = get_current_version()
    CliConfigManager.reset(current_version=current_version,
                           min_version=server_version.min_version)

    if LooseVersion(current_version) < LooseVersion(server_version.min_version):
        click.echo("""Your version of CLI ({}) is no longer compatible with server.""".format(
            current_version))
        if click.confirm("Do you want to upgrade to "
                         "version {} now?".format(server_version.latest_version)):
            pip_upgrade()
            sys.exit(0)
        else:
            indentation.puts("Your can manually run:")
            with indentation.indent(4):
                indentation.puts("pip install -U polyaxon-cli")
            indentation.puts(
                "to upgrade to the latest version `{}`".format(server_version.latest_version))

            sys.exit(0)
    elif LooseVersion(current_version) < LooseVersion(server_version.latest_version):
        indentation.puts("New version of CLI ({}) is now available. To upgrade run:".format(
            server_version.latest_version
        ))
        with indentation.indent(4):
            indentation.puts("pip install -U polyaxon-cli")
    elif LooseVersion(current_version) > LooseVersion(server_version.latest_version):
        indentation.puts("You version of CLI ({}) is ahead of the latest version "
                         "supported by Polyaxon Platform ({}) on your cluster, "
                         "and might be incompatible.".format(current_version,
                                                             server_version.latest_version))