コード例 #1
0
ファイル: project.py プロジェクト: zeyaddeeb/polyaxon
def get_project_or_local(project=None, is_cli: bool = False):
    from polyaxon import settings

    if not project and not ProjectConfigManager.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 = ProjectConfigManager.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
コード例 #2
0
ファイル: project.py プロジェクト: opentechfn/polyaxon
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
コード例 #3
0
ファイル: cache.py プロジェクト: opentechfn/polyaxon
def _cache_project(config, owner=None, project=None):
    if (ProjectConfigManager.is_initialized()
            and ProjectConfigManager.is_locally_initialized()):
        if _is_same_project(owner, project):
            ProjectConfigManager.set_config(config)
            return

    ProjectConfigManager.set_config(
        config, visibility=ProjectConfigManager.VISIBILITY_GLOBAL)
コード例 #4
0
ファイル: cache.py プロジェクト: opentechfn/polyaxon
def cache(config_manager, config, owner=None, project=None):
    if config_manager == ProjectConfigManager:
        _cache_project(config=config, project=project, owner=owner)

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

    if not _is_same_project(owner, project):
        return

    visibility = (ProjectConfigManager.VISIBILITY_LOCAL
                  if ProjectConfigManager.is_locally_initialized() else
                  ProjectConfigManager.VISIBILITY_GLOBAL)
    config_manager.set_config(config, visibility=visibility)
コード例 #5
0
ファイル: init.py プロジェクト: rimon-safesitehq/polyaxon
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))