Beispiel #1
0
def delete(ctx, _project):
    """Delete project.

    Uses /docs/core/cli/#caching
    """
    owner, project_name = get_project_or_local(_project
                                               or ctx.obj.get("project"),
                                               is_cli=True)

    if not click.confirm("Are sure you want to delete project `{}/{}`".format(
            owner, project_name)):
        click.echo("Existing without deleting project.")
        sys.exit(1)

    try:
        polyaxon_client = ProjectClient(owner=owner, project=project_name)
        polyaxon_client.delete()
        local_project = get_local_project()
        if local_project and (owner, project_name) == (
                local_project.owner,
                local_project.name,
        ):
            # Purge caching
            ProjectConfigManager.purge()
    except (ApiException, HTTPError) as e:
        handle_cli_error(e,
                         message="Could not delete project `{}/{}`.".format(
                             owner, project_name))
        sys.exit(1)

    Printer.print_success("Project `{}/{}` was delete successfully".format(
        owner, project_name))
Beispiel #2
0
def get_project_or_local(project=None, is_cli: bool = False):
    from polyaxon import settings

    if not project and not ProjectConfigManager.is_initialized():
        error_message = "Please provide a valid project or initialize a project in the current path."
        if is_cli:
            Printer.print_error(error_message)
            sys.exit(1)
        else:
            raise PolyaxonClientException(error_message)

    if project:
        owner, project_name = get_entity_info(project)
    else:
        project = get_local_project()

        owner, project_name = project.owner, project.name

    if not owner:
        owner = get_local_owner(is_cli=is_cli)

    if not owner and (not settings.CLI_CONFIG or settings.CLI_CONFIG.is_ce):
        owner = DEFAULT

    if not all([owner, project_name]):
        error_message = get_project_error_message(owner, project_name)
        if is_cli:
            Printer.print_error(error_message)
            sys.exit(1)
        else:
            raise PolyaxonClientException(error_message)
    return owner, project_name
Beispiel #3
0
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))