Beispiel #1
0
def purge(cache_only):
    """Purge the global config values."""
    if not cache_only:
        ClientConfigManager.purge()
        CliConfigManager.purge()
        AuthConfigManager.purge()
        UserConfigManager.purge()
    ProjectConfigManager.purge()
    RunConfigManager.purge()
    Printer.print_success("Configs was removed.")
Beispiel #2
0
def get_run_or_local(run_uuid=None, is_cli: bool = False):
    if run_uuid:
        return run_uuid
    if is_cli:
        return RunConfigManager.get_config_or_raise().uuid

    run = RunConfigManager.get_config()
    if run:
        return run.uuid
    return None
Beispiel #3
0
def get_run_or_local(run_uuid=None, is_cli: bool = False):
    if run_uuid:
        return run_uuid
    if is_cli:
        return RunConfigManager.get_config_or_raise().uuid

    try:
        run = RunConfigManager.get_config()
    except TypeError:
        Printer.print_error(
            "Found an invalid run config or run config cache, "
            "if you are using Polyaxon CLI please run: "
            "`polyaxon config purge --cache-only`",
            sys_exit=True,
        )
    if run:
        return run.uuid
    return None
Beispiel #4
0
def delete(ctx, project, uid):
    """Delete a run.

    Uses /docs/core/cli/#caching

    Example:

    \b
    $ polyaxon ops delete

    \b
    $ polyaxon ops delete --uid=8aac02e3a62a4f0aaa257c59da5eab80  # project is cached

    \b
    $ polyaxon ops delete --project=cats-vs-dogs -uid 8aac02e3a62a4f0aaa257c59da5eab80
    """
    owner, project_name, run_uuid = get_project_run_or_local(
        project or ctx.obj.get("project"),
        uid or ctx.obj.get("run_uuid"),
        is_cli=True,
    )
    if not click.confirm(
            "Are sure you want to delete run `{}`".format(run_uuid)):
        click.echo("Existing without deleting the run.")
        sys.exit(1)

    try:
        polyaxon_client = RunClient(owner=owner,
                                    project=project_name,
                                    run_uuid=run_uuid)
        polyaxon_client.delete()
        # Purge caching
        RunConfigManager.purge()
    except (ApiException, HTTPError) as e:
        handle_cli_error(e,
                         message="Could not delete run `{}`.".format(run_uuid))
        sys.exit(1)

    Printer.print_success("Run `{}` was delete successfully".format(run_uuid))
Beispiel #5
0
def get(ctx, project, uid, offline, offline_path):
    """Get run.

    Uses /docs/core/cli/#caching

    Examples for getting a run:

    \b
    $ polyaxon ops get  # if run is cached

    \b
    $ polyaxon ops get --uid=8aac02e3a62a4f0aaa257c59da5eab80 # project is cached

    \b
    $ polyaxon ops get --project=cats-vs-dogs -uid 8aac02e3a62a4f0aaa257c59da5eab80

    \b
    $ polyaxon ops get -p alain/cats-vs-dogs --uid=8aac02e3a62a4f0aaa257c59da5eab80
    """

    uid = uid or ctx.obj.get("run_uuid")

    if offline:
        offline_path = offline_path or container_contexts.CONTEXT_OFFLINE_ROOT
        offline_path = "{}/{}/run_data.json".format(offline_path, uid)
        if not os.path.exists(offline_path):
            Printer.print_error(
                f"Could not get offline run, the path `{offline_path}` "
                f"does not exist.")
            sys.exit(1)
        run_data = RunConfigManager.read_from_path(offline_path)
    else:
        owner, project_name, run_uuid = get_project_run_or_local(
            project or ctx.obj.get("project"),
            uid,
            is_cli=True,
        )

        try:
            polyaxon_client = RunClient(owner=owner,
                                        project=project_name,
                                        run_uuid=run_uuid)
            polyaxon_client.refresh_data()
            config = polyaxon_client.client.sanitize_for_serialization(
                polyaxon_client.run_data)
            cache.cache(
                config_manager=RunConfigManager,
                config=config,
                owner=owner,
                project=project_name,
            )
            run_data = polyaxon_client.run_data
        except (ApiException, HTTPError) as e:
            handle_cli_error(
                e,
                message="Could not load run `{}/{}/{}` info.".format(
                    owner, project_name, run_uuid),
            )
            sys.exit(1)

    get_run_details(run_data)
Beispiel #6
0
def ls(ctx, project, io, to_csv, query, sort, limit, offset, columns, offline,
       offline_path):
    """List runs for this project.

    Uses /docs/core/cli/#caching

    Examples:

    Get all runs:

    \b

    Get all runs with with status {created or running}, and
    creation date between 2018-01-01 and 2018-01-02, and params activation equal to sigmoid
    and metric loss less or equal to 0.2

    \b
    $ polyaxon ops ls \
    -q "status:created|running, started_at:2018-01-01..2018-01-02, \
    params.activation:sigmoid, metrics.loss:<=0.2"


    Get all runs sorted by update date:

    \b
    $ polyaxon ops ls -s "-updated_at"

    Get all runs of kind job:

    \b
    $ polyaxon ops ls -q "kind: job"

    Get all runs of kind service:

    \b
    $ polyaxon ops ls -q "kind: service"
    """
    if offline:
        offline_path = offline_path or container_contexts.CONTEXT_OFFLINE_ROOT
        offline_path_format = "{}/{{}}/run_data.json".format(offline_path)
        if not os.path.exists(offline_path) or not os.path.isdir(offline_path):
            Printer.print_error(
                f"Could not list offline runs, the path `{offline_path}` "
                f"does not exist or is not a directory.")
            sys.exit(1)
        results = []
        for uid in os.listdir(offline_path):
            run_path = offline_path_format.format(uid)
            if os.path.exists(run_path):
                results.append(RunConfigManager.read_from_path(run_path))
            else:
                Printer.print_warning(
                    f"Skipping run {uid}, offline data not found.")
    else:
        owner, project_name = get_project_or_local(project
                                                   or ctx.obj.get("project"),
                                                   is_cli=True)

        try:
            polyaxon_client = RunClient(owner=owner, project=project_name)
            response = polyaxon_client.list(limit=limit,
                                            offset=offset,
                                            query=query,
                                            sort=sort)
        except (ApiException, HTTPError) as e:
            handle_cli_error(
                e,
                message="Could not get runs for project `{}`.".format(
                    project_name))
            sys.exit(1)

        meta = get_meta_response(response)
        if meta:
            Printer.print_header("Runs for project `{}/{}`.".format(
                owner, project_name))
            Printer.print_header("Navigation:")
            dict_tabulate(meta)
        else:
            Printer.print_header("No runs found for project `{}/{}`.".format(
                owner, project_name))

        results = response.results

    objects = [Printer.add_status_color(o.to_dict()) for o in results]
    columns = validate_tags(columns)
    if io:
        objects, prefixed_columns = flatten_keys(
            objects=objects,
            columns=["inputs", "outputs"],
            columns_prefix={
                "inputs": "in",
                "outputs": "out"
            },
        )
        if columns:
            columns = {prefixed_columns.get(col, col) for col in columns}
        if to_csv:
            objects = list_dicts_to_csv(
                objects,
                include_attrs=columns,
                exclude_attrs=DEFAULT_EXCLUDE,
            )
        else:
            objects = list_dicts_to_tabulate(
                objects,
                include_attrs=columns,
                exclude_attrs=DEFAULT_EXCLUDE,
                humanize_values=True,
                upper_keys=True,
            )
    else:
        if to_csv:
            objects = list_dicts_to_csv(
                objects,
                include_attrs=columns,
                exclude_attrs=DEFAULT_EXCLUDE + ["inputs", "outputs"],
            )
        else:
            objects = list_dicts_to_tabulate(
                objects,
                include_attrs=columns,
                exclude_attrs=DEFAULT_EXCLUDE + ["inputs", "outputs"],
                humanize_values=True,
                upper_keys=True,
            )
    if objects:
        if to_csv:
            filename = "./results.csv"
            write_csv(objects, filename=filename)
            Printer.print_success("CSV file generated: `{}`".format(filename))
        else:
            Printer.print_header("Runs:")
            objects.pop("project_name", None)
            dict_tabulate(objects, is_list_dict=True)
Beispiel #7
0
 def test_default_props(self):
     assert RunConfigManager.is_all_visibility() is True
     assert RunConfigManager.IS_POLYAXON_DIR is True
     assert RunConfigManager.CONFIG_FILE_NAME == ".run"
     assert RunConfigManager.CONFIG == V1Run