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)
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)
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)
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)
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)
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)
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)
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)
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)
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)