예제 #1
0
def cache(config_manager, config):
    if config_manager == ProjectManager:
        ProjectManager.set_config(config)
        return
    # Set caching only if we have an initialized project
    if ProjectManager.is_initialized():
        config_manager.set_config(config)
예제 #2
0
def delete(ctx):
    """Delete project.

    Uses /docs/core/cli/#caching
    """
    owner, project_name = get_project_or_local(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)
        response = polyaxon_client.delete()
        local_project = ProjectManager.get_config()
        if local_project and (owner, project_name) == (
                local_project.user,
                local_project.name,
        ):
            # Purge caching
            ProjectManager.purge()
    except (ApiException, HTTPError) as e:
        handle_cli_error(e,
                         message="Could not delete project `{}/{}`.".format(
                             owner, project_name))
        sys.exit(1)

    if response.status_code == 204:
        Printer.print_success("Project `{}/{}` was delete successfully".format(
            owner, project_name))
예제 #3
0
def get_project_or_local(project=None, is_cli: bool = False):
    from polyaxon import settings

    if not project and not ProjectManager.is_initialized():
        if is_cli:
            Printer.print_error("Please provide a valid project.")
            sys.exit(1)
        else:
            raise PolyaxonClientException("Please provide a valid project.")

    if project:
        owner, project_name = get_project_info(project)
    else:
        project = ProjectManager.get_config()
        owner, project_name = project.owner, project.name

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

    if not all([owner, project_name]):
        if is_cli:
            Printer.print_error("Please provide a valid project.")
            sys.exit(1)
        else:
            raise PolyaxonClientException("Please provide a valid project.")
    return owner, project_name
예제 #4
0
def purge():
    """Purge the global config values."""
    ClientConfigManager.purge()
    CliConfigManager.purge()
    AuthConfigManager.purge()
    ProjectManager.purge()
    RunManager.purge()
    Printer.print_success("Config was removed.")
예제 #5
0
파일: upload.py 프로젝트: savvihub/polyaxon
def upload(sync=True):  # pylint:disable=assign-to-new-keyword
    """Upload code of the current directory while respecting the .polyaxonignore file."""
    project = ProjectManager.get_config_or_raise()
    files = IgnoreManager.get_unignored_filepaths()
    try:
        with create_project_tarfile(files, project.name) as filepath:
            with get_files_by_paths("repo", [filepath]) as (files, files_size):
                try:
                    PolyaxonClient().project.upload_repo(project.user,
                                                         project.name,
                                                         files,
                                                         files_size,
                                                         sync=sync)
                except (
                        PolyaxonHTTPError,
                        PolyaxonShouldExitError,
                        PolyaxonClientException,
                ) as e:
                    handle_cli_error(
                        e,
                        message="Could not upload code for project `{}`.".
                        format(project.name),
                    )
                    Printer.print_error(
                        "Check the project exists, "
                        "and that you have access rights, "
                        "this could happen as well when uploading large files. "
                        "Please also make sure that you have enough space to upload the data."
                    )
                    sys.exit(1)
                Printer.print_success("Files uploaded.")
    except Exception as e:
        handle_cli_error(e, message="Could not upload the file.")
        sys.exit(1)
예제 #6
0
파일: cache.py 프로젝트: zhaohb/polyaxon
def cache(config_manager, config, owner=None, project=None):
    if config_manager == ProjectManager:
        _cache_project(config=config, project=project, owner=owner)

    # Set caching only if we have an initialized project
    if not ProjectManager.is_initialized():
        return

    if not _is_same_project(owner, project):
        return

    visibility = (
        ProjectManager.VISIBILITY_LOCAL
        if ProjectManager.is_locally_initialized()
        else ProjectManager.VISIBILITY_GLOBAL
    )
    config_manager.set_config(config, visibility=visibility)
예제 #7
0
def get_project_or_local(project=None):
    if not project and not ProjectManager.is_initialized():
        Printer.print_error(
            "Please provide a valid project, or init a new project. "
            " {}".format(constants.INIT_COMMAND)
        )
        sys.exit(1)

    if project:
        user, project_name = get_project_info(project)
    else:
        project = ProjectManager.get_config()
        user, project_name = project.user, project.name

    if not all([user, project_name]):
        Printer.print_error(
            "Please provide a valid project, or init a new project."
            " {}".format(constants.INIT_COMMAND)
        )
        sys.exit(1)
    return user, project_name
예제 #8
0
def get_project_or_local(project=None, is_cli: bool = False):
    if not project and not ProjectManager.is_initialized():
        if is_cli:
            Printer.print_error("Please provide a valid project.")
            sys.exit(1)
        else:
            raise PolyaxonClientException("Please provide a valid project.")

    if project:
        user, project_name = get_project_info(project)
    else:
        project = ProjectManager.get_config()
        user, project_name = project.user, project.name

    if not all([user, project_name]):
        if is_cli:
            Printer.print_error("Please provide a valid project.")
            sys.exit(1)
        else:
            raise PolyaxonClientException("Please provide a valid project.")
    return user, project_name
예제 #9
0
파일: cache.py 프로젝트: zhaohb/polyaxon
def _cache_project(config, owner=None, project=None):
    if ProjectManager.is_initialized() and ProjectManager.is_locally_initialized():
        if _is_same_project(owner, project):
            ProjectManager.set_config(config)
            return

    ProjectManager.set_config(config, visibility=ProjectManager.VISIBILITY_GLOBAL)
예제 #10
0
파일: upload.py 프로젝트: wxrui/polyaxon
def upload():
    """N.B. This is not available in all distributions.

    Upload code of the current directory while respecting the .polyaxonignore file.
    """
    import sys

    from polyaxon.cli.errors import handle_cli_error
    from polyaxon.client import PolyaxonClient
    from polyaxon.exceptions import (
        PolyaxonClientException,
        PolyaxonHTTPError,
        PolyaxonShouldExitError,
    )
    from polyaxon.managers.ignore import IgnoreManager
    from polyaxon.managers.project import ProjectManager
    from polyaxon.utils.formatting import Printer
    from polyaxon.utils.path_utils import create_project_tarfile, get_files_by_paths

    project = ProjectManager.get_config_or_raise()
    files = IgnoreManager.get_unignored_filepaths()
    try:
        with create_project_tarfile(files, project.name) as filepath:
            with get_files_by_paths("repo", [filepath]) as (files, files_size):
                try:
                    PolyaxonClient().project.upload_repo(project.user,
                                                         project.name,
                                                         files,
                                                         files_size,
                                                         sync=sync)
                except (
                        PolyaxonHTTPError,
                        PolyaxonShouldExitError,
                        PolyaxonClientException,
                ) as e:
                    handle_cli_error(
                        e,
                        message="Could not upload code for project `{}`.".
                        format(project.name),
                    )
                    Printer.print_error(
                        "Check the project exists, "
                        "and that you have access rights, "
                        "this could happen as well when uploading large files. "
                        "Please also make sure that you have enough space to upload the data."
                    )
                    sys.exit(1)
                Printer.print_success("Files uploaded.")
    except Exception as e:
        handle_cli_error(e, message="Could not upload the file.")
        sys.exit(1)
예제 #11
0
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()
예제 #12
0
 def test_default_props(self):
     assert ProjectManager.is_all_visibility() is True
     assert ProjectManager.IS_POLYAXON_DIR is True
     assert ProjectManager.CONFIG_FILE_NAME == ".project"
     assert ProjectManager.CONFIG == V1Project
예제 #13
0
파일: cache.py 프로젝트: x10-utils/polyaxon
def cache(config_manager, response):
    # Set caching only if we have an initialized project
    if ProjectManager.is_initialized():
        config_manager.set_config(response)
예제 #14
0
파일: cache.py 프로젝트: zhaohb/polyaxon
def _is_same_project(owner=None, project=None):
    local_project = ProjectManager.get_config()
    if project and project == local_project.name:
        return not all([owner, local_project.owner]) or owner == local_project.owner