def get(ctx, save, filename): """Get a component info by component_name, or owner/component_name. Uses /docs/core/cli/#caching Examples: To get a component by name \b $ polyaxon hub get component_name To get a component by owner/name \b $ polyaxon hub get owner/component_name """ name = ctx.obj.get("name") if not name: Printer.print_error("Please provide a valid component name!") sys.exit(0) try: polyaxonfile = ConfigSpec.get_from(name, "hub").read() except Exception as e: handle_cli_error(e, message="Could not get component `{}`.".format(name)) sys.exit(1) specification = get_specification(data=polyaxonfile) polyaxonfile = yaml.dump(polyaxonfile) get_component_details(polyaxonfile=polyaxonfile, specification=specification) if save: filename = filename or "polyaxonfile.yaml" with open(filename, "w") as env_file: env_file.write(polyaxonfile)
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!")
def push(polyaxonfile, name, description, tags): """Push a new component version. If the name corresponds to an existing component version, it will be updated. Example: \b $ polyaxon hub push -f polyaxonfile.yaml --name=kaniko:latest --description="Tool to build container images" \b $ polyaxon hub push -f polyaxonfile.yaml --name=owner/name:v1 --description="Component description" """ if not name: Printer.print_error( "Please provide a name to create a component version.", command_help="hub push", sys_exit=True, ) owner, hub_name, version, is_version = get_info(None, name) tags = validate_tags(tags) if not polyaxonfile or not os.path.isfile(polyaxonfile): Printer.print_error( "Please provide a path to a polyaxonfile to create a component version.", command_help="hub push", sys_exit=True, ) try: plx_file = get_specification(data=polyaxonfile) except Exception as e: handle_cli_error(e, message="Polyaxonfile is not valid.") sys.exit(1) if not owner or not hub_name or not version: Printer.print_error( "Please provide a valid component version with --name=owner/hub-name:version. " ) sys.exit(1) polyaxon_client = PolyaxonClient() try: polyaxon_client.component_hub_v1.get_component_version(owner, hub_name, version) to_update = True except (ApiException, HTTPError): to_update = False if to_update: if not click.confirm( "A component version {}/{}:{} already exists. " "Do you want to push force this version?".format(owner, hub_name, version) ): click.echo("Existing without pushing component version.") sys.exit(1) try: hub_config = V1ComponentVersion( name=version, description=description, tags=tags, content=plx_file.to_dict(dump=True), ) if to_update: _version = polyaxon_client.component_hub_v1.update_component_version( owner, hub_name, version, hub_config, ) else: _version = polyaxon_client.component_hub_v1.create_component_version( owner, hub_name, hub_config, ) except (ApiException, HTTPError) as e: handle_cli_error( e, message="Could not create component version `{}`.".format(hub_name) ) sys.exit(1) Printer.print_success( "Component version `{}` was created successfully.".format(_version.name) ) click.echo( "You can view this component version on Polyaxon UI: {}".format( get_dashboard_url( subpath="{}/hub/{}/versions/{}".format(owner, hub_name, _version.name) ) ) )