def get_model_info(entity: str, entity_name: str, is_cli: bool = False): from polyaxon import settings if not entity: message = "Please provide a valid {}!".format(entity_name) if is_cli: Printer.print_error(message) sys.exit(1) else: raise PolyaxonClientException(message) owner = get_local_owner(is_cli=is_cli) if not owner and (not settings.CLI_CONFIG or settings.CLI_CONFIG.is_ce): owner = DEFAULT owner, entity_namespace, version = get_versioned_entity_info( entity=entity, entity_name=entity_name, default_owner=owner ) owner = owner or settings.AUTH_CONFIG.username if not all([owner, entity_name]): message = "Please provide a valid {}.".format(entity_name) if is_cli: Printer.print_error(message) sys.exit(1) else: raise PolyaxonClientException(message) return owner, entity_namespace, version
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
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 ls(owner, model, query, sort, limit, offset): """List model registry/versions by owner or owner/model.""" if owner and model: Printer.print_error( "Only an owner or a model is required, not both.", sys_exit=True ) if model: owner, model_registry, model_version, is_version = get_info(model, None) elif not owner: owner = get_local_owner(is_cli=True) if not owner: Printer.print_error( "Please provide a valid owner --owner/-o or a model --model/-m." ) sys.exit(1) def list_versions(): model_info = "<owner: {}> <model: {}>".format(owner, model_registry) try: polyaxon_client = PolyaxonClient() params = get_query_params( limit=limit, offset=offset, query=query, sort=sort ) response = polyaxon_client.model_registry_v1.list_model_versions( owner, model_registry, **params ) except (ApiException, HTTPError) as e: message = "Could not get list of model version." handle_cli_error(e, message=message) sys.exit(1) meta = get_meta_response(response) if meta: Printer.print_header("Versions for {}".format(model_info)) Printer.print_header("Navigation:") dict_tabulate(meta) else: Printer.print_header("No version found for {}".format(model_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("Model 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) if model: list_versions() else: list_models()