def check_cli_version(server_versions=None, current_version=None): """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_versions = server_versions or get_server_versions() current_version = current_version or get_current_version() cli_config = CliConfigManager.reset( current_version=current_version, server_versions=server_versions.to_dict() ) if LooseVersion(current_version) < LooseVersion(cli_config.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(cli_config.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( cli_config.latest_version ) ) sys.exit(0) elif LooseVersion(current_version) < LooseVersion(cli_config.latest_version): indentation.puts( "New version of CLI ({}) is now available. To upgrade run:".format( cli_config.latest_version ) ) with indentation.indent(4): indentation.puts("pip install -U polyaxon-cli") elif LooseVersion(current_version) > LooseVersion(cli_config.latest_version): indentation.puts( "Your version of CLI ({}) is ahead of the latest version " "supported by Polyaxon Platform ({}) on your cluster, " "and might be incompatible.".format( current_version, cli_config.latest_version ) )
def check_cli_version(config, is_cli: bool = True): """Check if the current cli version satisfies the server requirements""" from distutils.version import LooseVersion # pylint:disable=import-error min_version = clean_version_for_check(config.min_version) latest_version = clean_version_for_check(config.latest_version) current_version = clean_version_for_check(config.current_version) if not min_version or not latest_version or not current_version: if is_cli: Printer.print_error( "Could not get the min/latest versions from compatibility API.", sys_exit=True, ) else: return if LooseVersion(current_version) < LooseVersion(min_version): click.echo( """Your version of CLI ({}) is no longer compatible with server.""".format( config.current_version ) ) if click.confirm( "Do you want to upgrade to " "version {} now?".format(config.latest_version) ): pip_upgrade() sys.exit(0) else: indentation.puts("Your can manually run:") with indentation.indent(4): indentation.puts("pip install -U polyaxon") indentation.puts( "to upgrade to the latest version `{}`".format(config.latest_version) ) sys.exit(0) elif LooseVersion(current_version) < LooseVersion(latest_version): indentation.puts( "New version of CLI ({}) is now available. To upgrade run:".format( config.latest_version ) ) with indentation.indent(4): indentation.puts("pip install -U polyaxon") elif LooseVersion(current_version) > LooseVersion(latest_version): indentation.puts( "Your version of CLI ({}) is ahead of the latest version " "supported by Polyaxon Platform ({}) on your cluster, " "and might be incompatible.".format( config.current_version, config.latest_version ) )
def init(project, polyaxonfile, purge): """Initialize a new polyaxonfile specification.""" owner, project_name = get_project_or_local(project) try: polyaxon_client = PolyaxonClient() project_config = polyaxon_client.projects_v1.get_project( owner, project_name) except (ApiException, HTTPError) as e: Printer.print_error( "Make sure you have a project with this name `{}`".format(project)) handle_cli_error( e, message="You can a create new project with this command: " "polyaxon project create " "--name={} [--description=...] [--tags=...]".format(project_name), ) sys.exit(1) if purge: ProjectManager.purge() IgnoreManager.purge() init_project = False if ProjectManager.is_initialized(): local_project = ProjectManager.get_config() click.echo( "Warning! This project is already initialized with the following project:" ) with indentation.indent(4): indentation.puts("User: {}".format(local_project.user)) indentation.puts("Project: {}".format(local_project.name)) if click.confirm("Would you like to override this current config?", default=False): init_project = True else: init_project = True if init_project: ProjectManager.purge() config = polyaxon_client.api_client.sanitize_for_serialization( project_config) ProjectManager.set_config(config, init=True) Printer.print_success("Project was initialized") else: Printer.print_header("Project config was not changed.") init_ignore = False if IgnoreManager.is_initialized(): click.echo("Warning! Found a .polyaxonignore file.") if click.confirm("Would you like to override it?", default=False): init_ignore = True else: init_ignore = True if init_ignore: IgnoreManager.init_config() Printer.print_success("New .polyaxonignore file was created.") else: Printer.print_header(".polyaxonignore file was not changed.") if polyaxonfile: create_polyaxonfile() create_debug_polyaxonfile()
def init(project, git_connection, git_url, polyaxonfile, polyaxonignore): """Initialize a new local project and cache directory. Note: Make sure to add the local cache `.polyaxon` to your `.gitignore` and `.dockerignore` files. """ if not any( [project, git_connection, git_url, polyaxonfile, polyaxonignore]): Printer.print_warning( "`polyaxon init` did not receive any valid option.", command_help="polyaxon init", ) if project: owner, project_name = get_project_or_local(project, is_cli=True) try: polyaxon_client = ProjectClient(owner=owner, project=project_name) polyaxon_client.refresh_data() except (ApiException, HTTPError) as e: Printer.print_error( "Make sure you have a project with this name `{}`".format( project)) handle_cli_error( e, message="You can a create new project with this command: " "polyaxon project create " "--name={} [--description=...] [--tags=...]".format( project_name), ) sys.exit(1) init_project = False if ProjectConfigManager.is_initialized(): local_project = get_local_project() click.echo( "Warning! This project is already initialized with the following project:" ) with indentation.indent(4): indentation.puts("Owner: {}".format(local_project.owner)) indentation.puts("Project: {}".format(local_project.name)) if click.confirm("Would you like to override this current config?", default=False): init_project = True else: init_project = True if init_project: ProjectConfigManager.purge( visibility=ProjectConfigManager.VISIBILITY_LOCAL) config = polyaxon_client.client.sanitize_for_serialization( polyaxon_client.project_data) ProjectConfigManager.set_config( config, init=True, visibility=ProjectConfigManager.VISIBILITY_LOCAL) Printer.print_success("Project was initialized") Printer.print_header( "Make sure to add the local cache `.polyaxon` " "to your `.gitignore` and `.dockerignore` files.") else: Printer.print_header("Project config was not changed.") if git_connection or git_url: init_git = False if GitConfigManager.is_initialized(): click.echo("Warning! A {} file was found.".format( GitConfigManager.CONFIG_FILE_NAME)) if click.confirm("Would you like to override it?", default=False): init_git = True else: init_git = True if init_git: GitConfigManager.purge( visibility=GitConfigManager.VISIBILITY_LOCAL) config = GitConfigManager.CONFIG( connection=git_connection, git=V1GitType(url=git_url) if git_url else None, ) GitConfigManager.set_config(config=config, init=True) Printer.print_success("New {} file was created.".format( GitConfigManager.CONFIG_FILE_NAME)) else: Printer.print_header("{} file was not changed.".format( GitConfigManager.CONFIG_FILE_NAME)) if polyaxonfile: create_polyaxonfile() if polyaxonignore: init_ignore = False if IgnoreConfigManager.is_initialized(): click.echo("Warning! A {} file was found.".format( IgnoreConfigManager.CONFIG_FILE_NAME)) if click.confirm("Would you like to override it?", default=False): init_ignore = True else: init_ignore = True if init_ignore: IgnoreConfigManager.init_config() Printer.print_success("New {} file was created.".format( IgnoreConfigManager.CONFIG_FILE_NAME)) else: Printer.print_header("{} file was not changed.".format( IgnoreConfigManager.CONFIG_FILE_NAME))