def unbookmark(ctx): """Unbookmark build job. Uses [Caching](/references/polyaxon-cli/#caching) Examples: \b ```bash $ polyaxon build unbookmark ``` \b ```bash $ polyaxon build -b 2 unbookmark ``` """ user, project_name, _build = get_build_or_local(ctx.obj.get('project'), ctx.obj.get('build')) try: PolyaxonClient().build_job.unbookmark(user, project_name, _build) except (PolyaxonHTTPError, PolyaxonShouldExitError, PolyaxonClientException) as e: Printer.print_error( 'Could not unbookmark build job `{}`.'.format(_build)) Printer.print_error('Error message `{}`.'.format(e)) sys.exit(1) Printer.print_success("Build job unbookmarked.")
def get(ctx): """Get build job. Uses [Caching](/references/polyaxon-cli/#caching) Examples: \b ```bash $ polyaxon build -b 1 get ``` \b ```bash $ polyaxon build --build=1 --project=project_name get ``` """ user, project_name, _build = get_build_or_local(ctx.obj.get('project'), ctx.obj.get('build')) try: response = PolyaxonClient().build_job.get_build( user, project_name, _build) cache.cache(config_manager=BuildJobManager, response=response) except (PolyaxonHTTPError, PolyaxonShouldExitError, PolyaxonClientException) as e: Printer.print_error('Could not get build job `{}`.'.format(_build)) Printer.print_error('Error message `{}`.'.format(e)) sys.exit(1) get_build_details(response)
def resources(ctx, gpu): """Get build job resources. Uses [Caching](/references/polyaxon-cli/#caching) Examples: \b ```bash $ polyaxon build -b 2 resources ``` For GPU resources \b ```bash $ polyaxon build -b 2 resources --gpu ``` """ user, project_name, _build = get_build_or_local(ctx.obj.get('project'), ctx.obj.get('build')) try: message_handler = Printer.gpu_resources if gpu else Printer.resources PolyaxonClient().build_job.resources(user, project_name, _build, message_handler=message_handler) except (PolyaxonHTTPError, PolyaxonShouldExitError, PolyaxonClientException) as e: Printer.print_error( 'Could not get resources for build job `{}`.'.format(_build)) Printer.print_error('Error message `{}`.'.format(e)) sys.exit(1)
def stop(ctx, yes): """Stop build job. Uses [Caching](/references/polyaxon-cli/#caching) Examples: \b ```bash $ polyaxon build stop ``` \b ```bash $ polyaxon build -b 2 stop ``` """ user, project_name, _build = get_build_or_local(ctx.obj.get('project'), ctx.obj.get('build')) if not yes and not click.confirm("Are sure you want to stop " "job `{}`".format(_build)): click.echo('Existing without stopping build job.') sys.exit(0) try: PolyaxonClient().build_job.stop(user, project_name, _build) except (PolyaxonHTTPError, PolyaxonShouldExitError, PolyaxonClientException) as e: Printer.print_error('Could not stop build job `{}`.'.format(_build)) Printer.print_error('Error message `{}`.'.format(e)) sys.exit(1) Printer.print_success("Build job is being stopped.")
def delete(ctx): """Delete build job. Uses [Caching](/references/polyaxon-cli/#caching) Example: \b ```bash $ polyaxon build delete ``` \b ```bash $ polyaxon build -b 2 delete ``` """ user, project_name, _build = get_build_or_local(ctx.obj.get('project'), ctx.obj.get('build')) if not click.confirm("Are sure you want to delete build job `{}`".format(_build)): click.echo('Existing without deleting build job.') sys.exit(1) try: response = PolyaxonClient().build_job.delete_build( user, project_name, _build) # Purge caching BuildJobManager.purge() except (PolyaxonHTTPError, PolyaxonShouldExitError, PolyaxonClientException) as e: Printer.print_error('Could not delete job `{}`.'.format(_build)) Printer.print_error('Error message `{}`.'.format(e)) sys.exit(1) if response.status_code == 204: Printer.print_success("Build job `{}` was deleted successfully".format(_build))
def code(ctx): """Download code for build. Uses [Caching](/references/polyaxon-cli/#caching) Examples: \b ```bash $ polyaxon build -b 1 code ``` """ user, project_name, _build = get_build_or_local(ctx.obj.get('project'), ctx.obj.get('build')) try: code_ref = PolyaxonClient().build_job.get_code_reference(user, project_name, _build) commit = None if code_ref: commit = code_ref.commit Printer.print_header( 'Build has code ref: `{}`, downloading ...'.format(commit)) else: Printer.print_warning( 'Build has no code ref, downloading latest code...') PolyaxonClient().project.download_repo(user, project_name, commit=commit) except (PolyaxonHTTPError, PolyaxonShouldExitError, PolyaxonClientException) as e: Printer.print_error('Could not download outputs for experiment `{}`.'.format(_build)) Printer.print_error('Error message `{}`.'.format(e)) sys.exit(1) Printer.print_success('Files downloaded.')
def logs(ctx, past, follow, hide_time): """Get build logs. Uses [Caching](/references/polyaxon-cli/#caching) Examples: \b ```bash $ polyaxon build -b 2 logs ``` \b ```bash $ polyaxon build logs ``` """ user, project_name, _build = get_build_or_local(ctx.obj.get('project'), ctx.obj.get('build')) if past: try: response = PolyaxonClient().build_job.logs(user, project_name, _build, stream=False) get_logs_handler(handle_job_info=False, show_timestamp=not hide_time, stream=False)( response.content.decode().split('\n')) print() if not follow: return except (PolyaxonHTTPError, PolyaxonShouldExitError, PolyaxonClientException) as e: if not follow: Printer.print_error( 'Could not get logs for job `{}`.'.format(_build)) Printer.print_error('Error message `{}`.'.format(e)) sys.exit(1) try: PolyaxonClient().build_job.logs(user, project_name, _build, message_handler=get_logs_handler( handle_job_info=False, show_timestamp=not hide_time)) except (PolyaxonHTTPError, PolyaxonShouldExitError, PolyaxonClientException) as e: Printer.print_error( 'Could not get logs for build job `{}`.'.format(_build)) Printer.print_error('Error message `{}`.'.format(e)) sys.exit(1)
def statuses(ctx, page): """Get build job statuses. Uses [Caching](/references/polyaxon-cli/#caching) Examples: \b ```bash $ polyaxon build -b 2 statuses ``` """ user, project_name, _build = get_build_or_local(ctx.obj.get('project'), ctx.obj.get('build')) page = page or 1 try: response = PolyaxonClient().build_job.get_statuses(user, project_name, _build, page=page) except (PolyaxonHTTPError, PolyaxonShouldExitError, PolyaxonClientException) as e: Printer.print_error( 'Could not get status for build job `{}`.'.format(_build)) Printer.print_error('Error message `{}`.'.format(e)) sys.exit(1) meta = get_meta_response(response) if meta: Printer.print_header('Statuses for build job `{}`.'.format(_build)) Printer.print_header('Navigation:') dict_tabulate(meta) else: Printer.print_header( 'No statuses found for build job `{}`.'.format(_build)) objects = list_dicts_to_tabulate([ Printer.add_status_color(o.to_light_dict(humanize_values=True), status_key='status') for o in response['results'] ]) if objects: Printer.print_header("Statuses:") objects.pop('job', None) dict_tabulate(objects, is_list_dict=True)
def update(ctx, name, description, tags): """Update build. Uses [Caching](/references/polyaxon-cli/#caching) Example: \b ```bash $ polyaxon build -b 2 update --description="new description for my build" ``` """ user, project_name, _build = get_build_or_local(ctx.obj.get('project'), ctx.obj.get('build')) update_dict = {} if name: update_dict['name'] = name if description: update_dict['description'] = description tags = validate_tags(tags) if tags: update_dict['tags'] = tags if not update_dict: Printer.print_warning('No argument was provided to update the build.') sys.exit(0) try: response = PolyaxonClient().build_job.update_build( user, project_name, _build, update_dict) except (PolyaxonHTTPError, PolyaxonShouldExitError, PolyaxonClientException) as e: Printer.print_error('Could not update build `{}`.'.format(_build)) Printer.print_error('Error message `{}`.'.format(e)) sys.exit(1) Printer.print_success("Build updated.") get_build_details(response)