コード例 #1
0
ファイル: version.py プロジェクト: savvihub/polyaxon
def version():
    """Print the current version of the cli and platform."""
    server_versions = get_server_versions()
    cli_version = get_current_version()
    Printer.print_header("Current cli version: {}.".format(cli_version))
    Printer.print_header("Supported versions:")
    dict_tabulate(server_versions.to_dict())
コード例 #2
0
def ls(owner, limit, offset):
    """List projects.

    Uses /docs/core/cli/#caching
    """
    owner = owner or AuthConfigManager.get_value("username")
    if not owner:
        Printer.print_error(
            "Please login first or provide a valid owner --owner. "
            "`polyaxon login --help`")
        sys.exit(1)

    try:
        polyaxon_client = ProjectClient(owner=owner)
        response = polyaxon_client.list(limit=limit, offset=offset)
    except (ApiException, HTTPError) as e:
        handle_cli_error(e, message="Could not get list of projects.")
        sys.exit(1)

    meta = get_meta_response(response)
    if meta:
        Printer.print_header("Projects for current user")
        Printer.print_header("Navigation:")
        dict_tabulate(meta)
    else:
        Printer.print_header("No projects found for current user")

    objects = list_dicts_to_tabulate(
        [o.to_dict() for o in response.results],
        humanize_values=True,
        exclude_attrs=["uuid", "description"],
    )
    if objects:
        Printer.print_header("Projects:")
        dict_tabulate(objects, is_list_dict=True)
コード例 #3
0
def get_parallel_info(kind, concurrency, early_stopping=False, **kwargs):
    info = OrderedDict()
    info["Parallel kind"] = kind.lower()
    info["Concurrency"] = ("{} runs".format("sequential") if concurrency == 1
                           else "{} concurrent runs".format(concurrency))
    info["Early stopping"] = "activated" if early_stopping else "deactivated"
    if "n_runs" in kwargs:
        info["Num of runs to create"] = kwargs["n_runs"]

    dict_tabulate(info)
コード例 #4
0
def version(check):
    """Print the current version of the cli and platform."""
    Printer.print_header("Current cli version: {}.".format(pkg.VERSION))
    if check:
        config = set_versions_config()
        Printer.print_header("Platform:")
        dict_tabulate(config.installation)
        Printer.print_header("compatibility versions:")
        dict_tabulate(config.compatibility)
        check_cli_version(config)
コード例 #5
0
def get_project_details(project):
    if project.description:
        Printer.print_header("Project description:")
        click.echo("{}\n".format(project.description))

    response = dict_to_tabulate(project.to_dict(),
                                humanize_values=True,
                                exclude_attrs=["description"])

    Printer.print_header("Project info:")
    dict_tabulate(response)
コード例 #6
0
ファイル: registry.py プロジェクト: mort8Q/polyaxon
def get_model_version_details(response):
    metadata = response.metadata
    response = dict_to_tabulate(
        response.to_dict(), humanize_values=True, exclude_attrs=["metadata"]
    )

    Printer.print_header("Model version info:")
    dict_tabulate(response)

    if metadata:
        Printer.print_header("Metadata:")
        click.echo(metadata)
コード例 #7
0
def whoami():
    """Show current logged Polyaxon user."""
    try:
        polyaxon_client = PolyaxonClient()
        user = polyaxon_client.users_v1.get_user()
    except (ApiException, HTTPError) as e:
        handle_cli_error(e, message="Could not load user info.")
        sys.exit(1)

    response = dict_to_tabulate(user.to_dict(), exclude_attrs=["role"])

    Printer.print_header("User info:")
    dict_tabulate(response)
コード例 #8
0
def get_specification_details(specification):
    if specification.inputs:
        Printer.print_header("Component inputs:")
        objects = list_dicts_to_tabulate([i.to_dict() for i in specification.inputs])
        dict_tabulate(objects, is_list_dict=True)

    if specification.outputs:
        Printer.print_header("Component outputs:")
        objects = list_dicts_to_tabulate([o.to_dict() for o in specification.outputs])
        dict_tabulate(objects, is_list_dict=True)

    Printer.print_header("Content:")
    click.echo(specification.to_dict())
コード例 #9
0
ファイル: check.py プロジェクト: afcarl/polyaxon
def get_workflow_info(strategy, concurrency, early_stopping=False, **kwargs):
    info = OrderedDict()
    info["Workflow strategy"] = strategy.lower()
    info["Concurrency"] = (
        "{} runs".format("sequential")
        if concurrency == 1
        else "{} concurrent runs".format(concurrency)
    )
    info["Early stopping"] = "activated" if early_stopping else "deactivated"
    if "n_experiments" in kwargs:
        info["Experiments to create"] = kwargs["n_experiments"]

    dict_tabulate(info)
コード例 #10
0
ファイル: projects.py プロジェクト: smilee/polyaxon
def ls(owner, query, sort, limit, offset):
    """List projects.

    Uses /docs/core/cli/#caching
    """
    owner = owner or settings.AUTH_CONFIG.username
    if not owner and (not settings.CLI_CONFIG or settings.CLI_CONFIG.is_ce):
        owner = DEFAULT
    if not owner:
        Printer.print_error(
            "Please login first or provide a valid owner --owner. "
            "`polyaxon login --help`")
        sys.exit(1)

    try:
        polyaxon_client = ProjectClient(owner=owner)
        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 list of projects.")
        sys.exit(1)

    meta = get_meta_response(response)
    if meta:
        Printer.print_header("Projects for current user")
        Printer.print_header("Navigation:")
        dict_tabulate(meta)
    else:
        Printer.print_header("No projects found for current user")

    objects = list_dicts_to_tabulate(
        [o.to_dict() for o in response.results],
        humanize_values=True,
        exclude_attrs=[
            "uuid",
            "readme",
            "description",
            "is_deleted",
            "owner",
            "user_email",
            "teams",
            "role",
            "settings",
        ],
    )
    if objects:
        Printer.print_header("Projects:")
        dict_tabulate(objects, is_list_dict=True)
コード例 #11
0
    def _handle_run_statuses():
        if not conditions:
            return
        Printer.print_header("Latest status:")
        latest_status = Printer.add_status_color({"status": status},
                                                 status_key="status")
        click.echo("{}\n".format(latest_status["status"]))

        objects = list_dicts_to_tabulate([
            Printer.add_status_color(o.to_dict(), status_key="type")
            for o in conditions
        ])
        if objects:
            Printer.print_header("Conditions:")
            dict_tabulate(objects, is_list_dict=True)
コード例 #12
0
def get_component_version_details(response):
    content = response.content
    response = dict_to_tabulate(response.to_dict(),
                                humanize_values=True,
                                exclude_attrs=["content"])

    Printer.print_header("Component info:")
    dict_tabulate(response)

    if content:
        specification = get_specification(data=content)
        get_specification_details(specification)
    else:
        Printer.print_warning(
            "This component version does not have any polyaxonfile content!")
コード例 #13
0
ファイル: version.py プロジェクト: vishalbelsare/polyaxon
def version(check):
    """Print the current version of the cli and platform."""
    Printer.print_header("Current cli version: {}.".format(pkg.VERSION))
    if check:
        config = set_versions_config()
        Printer.print_header("Platform:")
        config_installation = dict_to_tabulate(
            config.installation,
            humanize_values=True,
            exclude_attrs=["hmac", "auth", "host"],
        )
        dict_tabulate(config_installation)
        Printer.print_header("Compatibility versions:")
        dict_tabulate(config.compatibility)
        check_cli_version(config)
コード例 #14
0
ファイル: bookmark.py プロジェクト: x10-utils/polyaxon
def runs(ctx, limit, offset):
    """List bookmarked runs for user.

    Uses [Caching](/references/polyaxon-cli/#caching)

    Examples:

    \b
    ```bash
    $ polyaxon bookmark experiments
    ```

    \b
    ```bash
    $ polyaxon bookmark -u adam experiments
    ```
    """
    user = get_username_or_local(ctx.obj.get("username"))

    try:
        params = get_query_params(limit=limit, offset=offset)
        polyaxon_client = PolyaxonClient()
        response = polyaxon_client.runs_v1.list_bookmarked_runs(user, **params)
    except (ApiException, HTTPError) as e:
        handle_cli_error(
            e,
            message="Could not get bookmarked experiments for user `{}`.".format(user),
        )
        sys.exit(1)

    meta = get_meta_response(response)
    if meta:
        Printer.print_header("Bookmarked experiments for user `{}`.".format(user))
        Printer.print_header("Navigation:")
        dict_tabulate(meta)
    else:
        Printer.print_header(
            "No bookmarked experiments found for user `{}`.".format(user)
        )

    objects = [
        Printer.add_status_color(o.to_light_dict(humanize_values=True))
        for o in response.results
    ]
    objects = list_dicts_to_tabulate(objects)
    if objects:
        Printer.print_header("Experiments:")
        dict_tabulate(objects, is_list_dict=True)
コード例 #15
0
ファイル: utils.py プロジェクト: vishalbelsare/polyaxon
def get_entity_details(entity: str, entity_name: str):
    if entity.description:
        Printer.print_header("{} description:".format(entity_name))
        click.echo("{}\n".format(entity.description))

    if entity.settings:
        Printer.print_header("{} settings:".format(entity_name))
        click.echo("{}\n".format(entity.settings.to_dict()))

    response = dict_to_tabulate(
        entity.to_dict(),
        humanize_values=True,
        exclude_attrs=["description", "settings", "readme"],
    )

    Printer.print_header("{} info:".format(entity_name))
    dict_tabulate(response)
コード例 #16
0
def whoami():
    """Show current logged Polyaxon Cloud or Polyaxon EE user."""
    try:
        polyaxon_client = PolyaxonClient()
        user = polyaxon_client.users_v1.get_user()
    except ApiException as e:
        if e.status == 403:
            session_expired()
        handle_cli_error(e,
                         message="Could not get the user info.",
                         sys_exit=True)
    except (ApiException, HTTPError) as e:
        handle_cli_error(e, message="Could not load user info.", sys_exit=True)

    response = dict_to_tabulate(user.to_dict(), exclude_attrs=["role"])
    Printer.print_header("User info:")
    dict_tabulate(response)
コード例 #17
0
ファイル: projects.py プロジェクト: opentechfn/polyaxon
def ls(owner, query, sort, limit, offset):
    """List projects.

    Uses /docs/core/cli/#caching
    """
    owner = owner or get_local_owner(is_cli=True)
    if not owner:
        Printer.print_error("Please provide a valid owner: --owner/-o.")
        sys.exit(1)

    try:
        polyaxon_client = ProjectClient(owner=owner)
        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 list of projects.")
        sys.exit(1)

    meta = get_meta_response(response)
    if meta:
        Printer.print_header("Projects for owner {}".format(owner))
        Printer.print_header("Navigation:")
        dict_tabulate(meta)
    else:
        Printer.print_header("No projects found for owner {}".format(owner))

    objects = list_dicts_to_tabulate(
        [o.to_dict() for o in response.results],
        humanize_values=True,
        exclude_attrs=[
            "uuid",
            "readme",
            "description",
            "owner",
            "user_email",
            "role",
            "settings",
        ],
    )
    if objects:
        Printer.print_header("Projects:")
        dict_tabulate(objects, is_list_dict=True)
コード例 #18
0
    def list_versions():
        component_info = "<owner: {}> <component: {}>".format(
            owner, component_hub)
        try:
            polyaxon_client = get_current_or_public_client()
            params = get_query_params(limit=limit,
                                      offset=offset,
                                      query=query,
                                      sort=sort)
            response = polyaxon_client.component_hub_v1.list_component_versions(
                owner, component_hub, **params)
        except (ApiException, HTTPError) as e:
            message = "Could not get list of component version."
            handle_cli_error(e, message=message)
            sys.exit(1)

        meta = get_meta_response(response)
        if meta:
            Printer.print_header("Versions for {}".format(component_info))
            Printer.print_header("Navigation:")
            dict_tabulate(meta)
        else:
            Printer.print_header(
                "No version found for {}".format(component_info))

        objects = list_dicts_to_tabulate(
            [o.to_dict() for o in response.results],
            humanize_values=True,
            exclude_attrs=[
                "uuid",
                "readme",
                "description",
                "owner",
                "owner",
                "role",
                "settings",
                "content",
                "live_state",
            ],
        )
        if objects:
            Printer.print_header("Component versions:")
            dict_tabulate(objects, is_list_dict=True)
コード例 #19
0
def get_run_details(run):  # pylint:disable=redefined-outer-name
    if run.description:
        Printer.print_header("Run description:")
        click.echo("{}\n".format(run.description))

    if run.inputs:
        Printer.print_header("Run inputs:")
        dict_tabulate(run.inputs)

    if run.outputs:
        Printer.print_header("Run outputs:")
        dict_tabulate(run.outputs)

    if run.settings:
        Printer.print_header("Run settings:")
        dict_tabulate(run.settings.to_dict())

    if run.meta_info:
        Printer.print_header("Run meta info:")
        dict_tabulate(run.meta_info)

    response = Printer.add_status_color(run.to_dict())
    response = dict_to_tabulate(
        response,
        humanize_values=True,
        exclude_attrs=[
            "description",
            "readme",
            "content",
            "raw_content",
            "inputs",
            "outputs",
            "is_managed",
            "status_conditions",
            "settings",
            "meta_info",
            "graph",
        ],
    )

    Printer.print_header("Run info:")
    dict_tabulate(response)
コード例 #20
0
def get(keys):
    """Get the global config values by keys.

    Example:

    \b
    $ polyaxon config get host port
    """
    _config = ClientConfigManager.get_config_or_default()

    if not keys:
        return

    print_values = {}
    for key in keys:
        if hasattr(_config, key):
            print_values[key] = getattr(_config, key)
        else:
            click.echo("Key `{}` is not recognised.".format(key))

    dict_tabulate(print_values)
コード例 #21
0
ファイル: config.py プロジェクト: opentechfn/polyaxon
def show():
    """Show the current cli, client, and user configs."""
    _config = ClientConfigManager.get_config_or_default()
    Printer.print_header("Client config:")
    dict_tabulate(_config.to_dict())
    _config = CliConfigManager.get_config_or_default()
    if _config:
        Printer.print_header("CLI config:")
        if _config.current_version:
            click.echo("Version {}".format(_config.current_version))
        else:
            Printer.print_warning("This cli is not configured.")
        if _config.installation:
            config_installation = dict_to_tabulate(
                _config.installation,
                humanize_values=True,
                exclude_attrs=["hmac", "auth", "host"],
            )
            dict_tabulate(config_installation)
        else:
            Printer.print_warning(
                "This cli is not connected to a Polyaxon Host.")
    _config = UserConfigManager.get_config_or_default()
    if _config:
        Printer.print_header("User config:")
        config_user = dict_to_tabulate(
            _config.to_dict(),
            humanize_values=True,
            exclude_attrs=["theme"],
        )
        dict_tabulate(config_user)
コード例 #22
0
ファイル: config.py プロジェクト: opentechfn/polyaxon
def get(keys):
    """Get the specific keys from the global configuration.

    Example:

    \b
    $ polyaxon config get host verify-ssl
    """
    _config = ClientConfigManager.get_config_or_default()

    if not keys:
        return

    print_values = {}
    for key in keys:
        key = key.replace("-", "_")
        if hasattr(_config, key):
            print_values[key] = getattr(_config, key)
        else:
            click.echo("Key `{}` is not recognised.".format(key))

    dict_tabulate(print_values)
コード例 #23
0
def get_component_details(polyaxonfile, specification):
    if specification.name:
        Printer.print_header("Component description:")
        click.echo("{}\n".format(specification.description))
    if specification.description:
        Printer.print_header("Component description:")
        click.echo("{}\n".format(specification.description))

    if specification.inputs:
        Printer.print_header("Component inputs:")
        objects = list_dicts_to_tabulate(
            [i.to_dict() for i in specification.inputs])
        dict_tabulate(objects, is_list_dict=True)

    if specification.outputs:
        Printer.print_header("Component outputs:")
        objects = list_dicts_to_tabulate(
            [o.to_dict() for o in specification.outputs])
        dict_tabulate(objects, is_list_dict=True)

    Printer.print_header("Component:")
    click.echo(polyaxonfile)
コード例 #24
0
ファイル: registry.py プロジェクト: vishalbelsare/polyaxon
    def list_models():
        try:
            polyaxon_client = PolyaxonClient()
            params = get_query_params(limit=limit,
                                      offset=offset,
                                      query=query,
                                      sort=sort)
            response = polyaxon_client.model_registry_v1.list_model_registries(
                owner, **params)
        except (ApiException, HTTPError) as e:
            message = "Could not get list of models."
            handle_cli_error(e, message=message)
            sys.exit(1)

        meta = get_meta_response(response)
        if meta:
            Printer.print_header("Models for owner {}".format(owner))
            Printer.print_header("Navigation:")
            dict_tabulate(meta)
        else:
            Printer.print_header(
                "No model registry found for owner {}".format(owner))

        objects = list_dicts_to_tabulate(
            [o.to_dict() for o in response.results],
            humanize_values=True,
            exclude_attrs=[
                "uuid",
                "readme",
                "description",
                "owner",
                "role",
                "settings",
                "live_state",
            ],
        )
        if objects:
            Printer.print_header("Models:")
            dict_tabulate(objects, is_list_dict=True)
コード例 #25
0
    def _get_run_statuses():
        try:
            for status, conditions in get_run_statuses(owner, project_name,
                                                       run_uuid, watch):
                if not conditions:
                    continue
                Printer.print_header("Latest status:")
                latest_status = Printer.add_status_color({"status": status},
                                                         status_key="status")
                click.echo("{}\n".format(latest_status["status"]))

                objects = list_dicts_to_tabulate([
                    Printer.add_status_color(o.to_dict(), status_key="type")
                    for o in conditions
                ])
                if objects:
                    Printer.print_header("Conditions:")
                    dict_tabulate(objects, is_list_dict=True)
        except (ApiException, HTTPError, PolyaxonClientException) as e:
            handle_cli_error(
                e, message="Could get status for run `{}`.".format(run_uuid))
            sys.exit(1)
コード例 #26
0
def config(list):  # pylint:disable=redefined-builtin
    """Set and get the global configurations."""
    if list:
        _config = ClientConfigManager.get_config_or_default()
        Printer.print_header("Current config:")
        dict_tabulate(_config.to_dict())
コード例 #27
0
def ls(ctx, io, query, sort, limit, offset):
    """List runs for this project.

    Uses [Caching](/references/polyaxon-cli/#caching)

    Examples:

    Get all runs:

    \b
    ```bash
    $ polyaxon project runs
    ```

    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
    ```bash
    $ polyaxon project runs \
      -q "status:created|running, started_at:2018-01-01..2018-01-02, \
          params.activation:sigmoid, metric.loss:<=0.2"
    ```

    Get all runs sorted by update date

    \b
    ```bash
    $ polyaxon project runs -s "-updated_at"
    ```
    """
    owner, project_name = get_project_or_local(ctx.obj.get("project"))

    try:
        polyaxon_client = PolyaxonClient()
        params = get_query_params(limit=limit,
                                  offset=offset,
                                  query=query,
                                  sort=sort)
        response = polyaxon_client.runs_v1.list_runs(owner=owner,
                                                     project=project_name,
                                                     **params)
    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("Experiments 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))

    objects = [Printer.add_status_color(o.to_dict()) for o in response.results]

    if io:
        objects = get_runs_with_keys(objects=objects,
                                     params_keys=["inputs", "outputs"])
        objects = list_dicts_to_tabulate(
            objects,
            exclude_attrs=[
                "owner",
                "project",
                "description",
                "content",
                "deleted",
                "readme",
                "run_env",
            ],
        )
    else:
        objects = list_dicts_to_tabulate(
            objects,
            exclude_attrs=[
                "owner",
                "project",
                "description",
                "content",
                "deleted",
                "readme",
                "run_env",
                "inputs",
                "outputs",
            ],
        )
    if objects:
        Printer.print_header("Runs:")
        objects.pop("project_name", None)
        dict_tabulate(objects, is_list_dict=True)
コード例 #28
0
ファイル: operations.py プロジェクト: jcims123/polyaxon
def ls(ctx, io, query, sort, limit, offset, columns):
    """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"
    """
    owner, project_name = get_project_or_local(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)
        )

    objects = [Printer.add_status_color(o.to_dict()) for o in response.results]

    if io:
        objects = get_runs_with_keys(objects=objects, params_keys=["inputs", "outputs"])
        objects = list_dicts_to_tabulate(
            objects,
            include_attrs=validate_tags(columns),
            exclude_attrs=[
                "owner",
                "project",
                "description",
                "content",
                "raw_content",
                "deleted",
                "readme",
                "settings",
                "meta_info",
                "original",
                "pipeline",
                "role",
                "status_conditions",
                "is_helper",
            ],
        )
    else:
        objects = list_dicts_to_tabulate(
            objects,
            include_attrs=validate_tags(columns),
            exclude_attrs=[
                "owner",
                "project",
                "description",
                "content",
                "raw_content",
                "deleted",
                "readme",
                "inputs",
                "outputs",
                "settings",
                "meta_info",
                "original",
                "pipeline",
                "role",
                "status_conditions",
                "is_helper",
            ],
        )
    if objects:
        Printer.print_header("Runs:")
        objects.pop("project_name", None)
        dict_tabulate(objects, is_list_dict=True)
コード例 #29
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)
コード例 #30
0
def ls(ctx, io, to_csv, query, sort, limit, offset, columns):
    """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"
    """
    owner, project_name = get_project_or_local(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))

    objects = [Printer.add_status_color(o.to_dict()) for o in response.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,
            )
        else:
            objects = list_dicts_to_tabulate(
                objects,
                include_attrs=columns,
                exclude_attrs=DEFAULT_EXCLUDE,
                humanize_values=True,
                upper_keys=True,
            )
    if objects:
        if to_csv:
            write_csv(objects)
        else:
            Printer.print_header("Runs:")
            objects.pop("project_name", None)
            dict_tabulate(objects, is_list_dict=True)