def get(ctx): """Get info for current project, by project_name, or owner/project_name. Uses /docs/core/cli/#caching Examples: To get current project: \b $ polyaxon project get To get a project by name \b $ polyaxon project get owner/project """ owner, project_name = get_project_or_local(ctx.obj.get("project"), is_cli=True) try: polyaxon_client = ProjectClient(owner=owner, project=project_name) polyaxon_client.refresh_data() config = polyaxon_client.client.sanitize_for_serialization( polyaxon_client.project_data) cache.cache(config_manager=ProjectManager, config=config) except (ApiException, HTTPError) as e: handle_cli_error( e, message="Could not get project `{}`.".format(project_name)) sys.exit(1) get_project_details(polyaxon_client.project_data)
def delete(ctx): """Delete project. Uses /docs/core/cli/#caching """ owner, project_name = get_project_or_local(ctx.obj.get("project"), is_cli=True) if not click.confirm("Are sure you want to delete project `{}/{}`".format( owner, project_name)): click.echo("Existing without deleting project.") sys.exit(1) try: polyaxon_client = ProjectClient(owner=owner, project=project_name) response = polyaxon_client.delete() local_project = ProjectManager.get_config() if local_project and (owner, project_name) == ( local_project.user, local_project.name, ): # Purge caching ProjectManager.purge() except (ApiException, HTTPError) as e: handle_cli_error(e, message="Could not delete project `{}/{}`.".format( owner, project_name)) sys.exit(1) if response.status_code == 204: Printer.print_success("Project `{}/{}` was delete successfully".format( owner, project_name))
def __init__( self, owner: str = None, project: str = None, run_uuid: str = None, client: PolyaxonClient = None, ): try: owner, project = get_project_or_local( get_project_full_name(owner=owner, project=project)) except PolyaxonClientException: pass if project is None: if settings.CLIENT_CONFIG.is_managed: owner, project, _run_uuid = get_run_info() run_uuid = run_uuid or _run_uuid else: raise PolyaxonClientException( "Please provide a valid project.") if not owner or not project: raise PolyaxonClientException( "Please provide a valid project with owner.") self.client = client if not (self.client or settings.CLIENT_CONFIG.is_offline): self.client = PolyaxonClient() self._owner = owner self._project = project self._run_uuid = get_run_or_local(run_uuid) self._run_data = polyaxon_sdk.V1Run() self._namespace = None
def create(ctx, name, description, tags, private, init): """Create a new project. Uses /docs/core/cli/#caching Example: \b $ polyaxon project create --project=cats-vs-dogs --description="Image Classification with DL" \b $ polyaxon project create --project=owner/name --description="Project Description" """ if not name: Printer.print_error( "Please login provide a name to create a project.", command_help="project create", sys_exit=True, ) owner, project_name = get_project_or_local(name or ctx.obj.get("project"), is_cli=True) owner = owner or settings.AUTH_CONFIG.username if not owner and (not settings.CLI_CONFIG or settings.CLI_CONFIG.is_ce): owner = DEFAULT tags = validate_tags(tags) if not owner: Printer.print_error( "Please login first or provide a valid name with owner --name=owner/project. " "`polyaxon login --help`") sys.exit(1) try: project_config = V1Project(name=project_name, description=description, tags=tags, is_public=not private) polyaxon_client = ProjectClient(owner=owner) _project = polyaxon_client.create(project_config) config = polyaxon_client.client.sanitize_for_serialization(_project) cache.cache(config_manager=ProjectConfigManager, config=config) except (ApiException, HTTPError) as e: handle_cli_error( e, message="Could not create project `{}`.".format(project_name)) sys.exit(1) Printer.print_success("Project `{}` was created successfully.".format( _project.name)) click.echo("You can view this project on Polyaxon UI: {}".format( get_dashboard_url(subpath="{}/{}".format(owner, _project.name)))) if init: ctx.obj = {} ctx.invoke(init_project, project="{}/{}".format(owner, project_name))
def update(ctx, name, description, private): """Update project. Uses [Caching](/references/polyaxon-cli/#caching) Example: \b ```bash $ polyaxon update foobar --description="Image Classification with DL using TensorFlow" ``` \b ```bash $ polyaxon update mike1/foobar --description="Image Classification with DL using TensorFlow" ``` \b ```bash $ polyaxon update --tags="foo, bar" ``` """ owner, project_name = get_project_or_local(ctx.obj.get("project"), is_cli=True) update_dict = {} if name: update_dict["name"] = name if description: update_dict["description"] = description if private is not None: update_dict["is_public"] = not private if not update_dict: Printer.print_warning( "No argument was provided to update the project.") sys.exit(1) try: polyaxon_client = ProjectClient(owner=owner) response = polyaxon_client.update(update_dict) except (ApiException, HTTPError) as e: handle_cli_error( e, message="Could not update project `{}`.".format(project_name)) sys.exit(1) Printer.print_success("Project updated.") get_project_details(response)
def update(ctx, _project, name, description, tags, private): """Update project. Uses /docs/core/cli/#caching Example: \b $ polyaxon project update foobar --description="Image Classification with DL using TensorFlow" \b $ polyaxon project update mike1/foobar --description="Image Classification with DL using TensorFlow" \b $ polyaxon update --tags="foo, bar" """ owner, project_name = get_project_or_local(_project or ctx.obj.get("project"), is_cli=True) 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 private is not None: update_dict["is_public"] = not private if not update_dict: Printer.print_warning( "No argument was provided to update the project.") sys.exit(1) try: polyaxon_client = ProjectClient(owner=owner) response = polyaxon_client.update(update_dict) except (ApiException, HTTPError) as e: handle_cli_error( e, message="Could not update project `{}`.".format(project_name)) sys.exit(1) Printer.print_success("Project updated.") get_entity_details(response, "Project")
def dashboard(ctx, yes, url): """Open this operation's dashboard details in browser.""" owner, project_name = get_project_or_local(ctx.obj.get("project"), is_cli=True) dashboard_url = clean_host(settings.CLIENT_CONFIG.host) project_url = "{}/{}/{}/".format(dashboard_url, owner, project_name) if url: Printer.print_header("The dashboard is available at: {}".format(project_url)) sys.exit(0) if not yes: click.confirm( "Dashboard page will now open in your browser. Continue?", abort=True, default=True, ) click.launch(project_url)
def dashboard(ctx, _project, yes, url): """Open this operation's dashboard details in browser.""" owner, project_name = get_project_or_local( _project or ctx.obj.get("project"), is_cli=True ) project_url = get_dashboard_url(subpath="{}/{}".format(owner, project_name)) if url: Printer.print_header("The dashboard is available at: {}".format(project_url)) sys.exit(0) if not yes: click.confirm( "Dashboard page will now open in your browser. Continue?", abort=True, default=True, ) click.launch(project_url)
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 run( ctx, project, polyaxonfile, python_module, url, hub, name, tags, description, log, upload, upload_from, upload_to, watch, local, params, presets, queue, nocache, cache, eager, git_preset, git_revision, ignore_template, ): """Run polyaxonfile specification. Examples: \b $ polyaxon run -f file -f file_override ... Run and set description and tags for this run \b $ polyaxon run -f file --description="Description of the current run" --tags="foo, bar, moo" Run and set a unique name for this run \b polyaxon run --name=foo Run for a specific project \b $ polyaxon run -p project1 -f file.yaml Run with updated params \b $ polyaxon run -p project1 -f file.yaml -P param1=234.2 -P param2=relu If a python file contains a component main, you can run that component \b $ polyaxon run -pm path/to/my-component.py If a python file contains more than one component, you can specify the component to run \b $ polyaxon run -pm path/to/my-component.py:componentA Uploading from everything in the current folder to the default uploads path \b $ polyaxon run ... -u Uploading from everything in the current folder to a custom path, e.g. code \b $ polyaxon run ... -u-to code Uploading from everything from a sub-folder, e.g. ./code to the a custom path, e.g. new-code \b $ polyaxon run ... -u-from ./code -u-to new-code """ if cache and nocache: Printer.print_error( "You can't use `--cache` and `--nocache` at the same.", sys_exit=True ) if (upload_to or upload_from) and not upload: upload = True if upload and eager: Printer.print_error( "You can't use `--upload` and `--eager` at the same.", sys_exit=True ) git_init = None if git_preset or git_revision: # Check that the current path was initialized if not GitConfigManager.is_initialized(): Printer.print_error( "You can't use `--git-preset [--git-revision]`, " "the current path is not initialized with a valid git connection or a git url, " "please run `polyaxon init [--git-connection] [--git-url]` " "to set a valid git configuration.", sys_exit=True, ) git_init = GitConfigManager.get_config() if git_init.git is None: GitConfigManager.purge(visibility=GitConfigManager.VISIBILITY_LOCAL) Printer.print_error( "Polyaxon could not start a new run with the `[--git-preset] or [--git-revision]`. " "The current path is initialized with " "an invalid git connection or an invalid git url.\n" "please run `polyaxon init [--git-connection] [--git-url]` " "to properly initialize the current path.", sys_exit=True, ) if git_revision: git_init.git.revision = git_revision elif code_reference.is_git_initialized(path="."): if code_reference.is_dirty(path="."): Printer.print_warning( "Polyaxon detected uncommitted changes in the current git repo!" ) commit_hash = code_reference.get_commit() git_init.git.revision = commit_hash else: Printer.print_warning( "Polyaxon could not find a valid git repo, " "and will not add the current commit to the git initializer." ) presets = validate_tags(presets) op_spec = check_polyaxonfile( polyaxonfile=polyaxonfile, python_module=python_module, url=url, hub=hub, params=params, presets=presets, queue=queue, cache=cache, nocache=nocache, verbose=False, eager=eager, git_init=git_init, ignore_template=ignore_template, ) if ignore_template: op_spec.disable_template() if op_spec.is_template(): click.echo("Please customize the specification or disable the template.") sys.exit(1) owner, project_name = get_project_or_local(project, is_cli=True) tags = validate_tags(tags) if local: try: compiled_operation = OperationSpecification.compile_operation(op_spec) compiled_operation = ( CompiledOperationSpecification.apply_operation_contexts( compiled_operation ) ) except (PolyaxonSchemaError, ValidationError): Printer.print_error( "Could not run this polyaxonfile locally, " "a context is required to resolve it dependencies." ) sys.exit(1) docker_run( ctx=ctx, name=name, owner=owner, project_name=project_name, description=description, tags=tags, compiled_operation=compiled_operation, log=log, ) elif settings.CLIENT_CONFIG.no_api: k8s_run( ctx=ctx, name=name, owner=owner, project_name=project_name, description=description, tags=tags, op_spec=op_spec, log=log, ) else: platform_run( ctx=ctx, name=name, owner=owner, project_name=project_name, description=description, tags=tags, op_spec=op_spec, log=log, upload=upload, upload_to=upload_to, upload_from=upload_from, watch=watch, eager=eager, )
def run( ctx, project, polyaxonfile, python_module, url, hub, name, tags, description, upload, log, watch, local, conda_env, params, profile, queue, nocache, ): """Run polyaxonfile specification. Examples: \b $ polyaxon run -f file -f file_override ... Upload before running \b $ polyaxon run -f file -u Run and set description and tags for this run \b $ polyaxon run -f file -u --description="Description of the current run" --tags="foo, bar, moo" Run and set a unique name for this run \b polyaxon run --name=foo Run for a specific project \b $ polyaxon run -p project1 -f file.yaml Run with updated params \b $ polyaxon run -p project1 -f file.yaml -P param1=234.2 -P param2=relu If a python file contains a component main, you can run that component \b polyaxon run -pm path/to/my-component.py If a python file contains more than one component, you can specify the component to run \b polyaxon run -pm path/to/my-component.py:componentA """ op_spec = check_polyaxonfile( polyaxonfile=polyaxonfile, python_module=python_module, url=url, hub=hub, params=params, profile=profile, queue=queue, nocache=nocache, log=False, ) owner, project_name = get_project_or_local(project, is_cli=True) tags = validate_tags(tags) if local: try: compiled_operation = OperationSpecification.compile_operation(op_spec) compiled_operation = CompiledOperationSpecification.apply_context( compiled_operation ) except (PolyaxonSchemaError, ValidationError): Printer.print_error( "Could not run this polyaxonfile locally, " "a context is required to resolve it dependencies." ) sys.exit(1) docker_run( ctx=ctx, name=name, owner=owner, project_name=project_name, description=description, tags=tags, compiled_operation=compiled_operation, log=log, ) elif settings.CLIENT_CONFIG.no_api: k8s_run( ctx=ctx, name=name, owner=owner, project_name=project_name, description=description, tags=tags, op_spec=op_spec, upload=upload, log=log, can_upload=all([upload, project]), ) else: platform_run( ctx=ctx, name=name, owner=owner, project_name=project_name, description=description, tags=tags, op_spec=op_spec, upload=upload, log=log, watch=watch, can_upload=all([upload, project]), )
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 init(project, git_connection, git_url, polyaxonfile, polyaxonignore): """Initialize a new local project and cache directory. Note: Make sure to add the local cache `.polyaxon` to your `.gitignore` and `.dockerignore` files. """ if not any( [project, git_connection, git_url, polyaxonfile, polyaxonignore]): Printer.print_warning( "`polyaxon init` did not receive any valid option.", command_help="polyaxon init", ) if project: owner, project_name = get_project_or_local(project, is_cli=True) try: polyaxon_client = ProjectClient(owner=owner, project=project_name) polyaxon_client.refresh_data() except (ApiException, HTTPError) as e: Printer.print_error( "Make sure you have a project with this name `{}`".format( project)) handle_cli_error( e, message="You can a create new project with this command: " "polyaxon project create " "--name={} [--description=...] [--tags=...]".format( project_name), ) sys.exit(1) init_project = False if ProjectConfigManager.is_initialized(): local_project = get_local_project() click.echo( "Warning! This project is already initialized with the following project:" ) with indentation.indent(4): indentation.puts("Owner: {}".format(local_project.owner)) indentation.puts("Project: {}".format(local_project.name)) if click.confirm("Would you like to override this current config?", default=False): init_project = True else: init_project = True if init_project: ProjectConfigManager.purge( visibility=ProjectConfigManager.VISIBILITY_LOCAL) config = polyaxon_client.client.sanitize_for_serialization( polyaxon_client.project_data) ProjectConfigManager.set_config( config, init=True, visibility=ProjectConfigManager.VISIBILITY_LOCAL) Printer.print_success("Project was initialized") Printer.print_header( "Make sure to add the local cache `.polyaxon` " "to your `.gitignore` and `.dockerignore` files.") else: Printer.print_header("Project config was not changed.") if git_connection or git_url: init_git = False if GitConfigManager.is_initialized(): click.echo("Warning! A {} file was found.".format( GitConfigManager.CONFIG_FILE_NAME)) if click.confirm("Would you like to override it?", default=False): init_git = True else: init_git = True if init_git: GitConfigManager.purge( visibility=GitConfigManager.VISIBILITY_LOCAL) config = GitConfigManager.CONFIG( connection=git_connection, git=V1GitType(url=git_url) if git_url else None, ) GitConfigManager.set_config(config=config, init=True) Printer.print_success("New {} file was created.".format( GitConfigManager.CONFIG_FILE_NAME)) else: Printer.print_header("{} file was not changed.".format( GitConfigManager.CONFIG_FILE_NAME)) if polyaxonfile: create_polyaxonfile() if polyaxonignore: init_ignore = False if IgnoreConfigManager.is_initialized(): click.echo("Warning! A {} file was found.".format( IgnoreConfigManager.CONFIG_FILE_NAME)) if click.confirm("Would you like to override it?", default=False): init_ignore = True else: init_ignore = True if init_ignore: IgnoreConfigManager.init_config() Printer.print_success("New {} file was created.".format( IgnoreConfigManager.CONFIG_FILE_NAME)) else: Printer.print_header("{} file was not changed.".format( IgnoreConfigManager.CONFIG_FILE_NAME))
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"), 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("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", "kind", ], ) else: objects = list_dicts_to_tabulate( objects, exclude_attrs=[ "owner", "project", "description", "content", "deleted", "readme", "inputs", "outputs", "kind", ], ) 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 run( ctx, project, polyaxonfile, python_module, url, hub, name, tags, description, log, watch, local, params, presets, queue, nocache, eager, git_preset, git_revision, ignore_template, ): """Run polyaxonfile specification. Examples: \b $ polyaxon run -f file -f file_override ... Run and set description and tags for this run \b $ polyaxon run -f file --description="Description of the current run" --tags="foo, bar, moo" Run and set a unique name for this run \b polyaxon run --name=foo Run for a specific project \b $ polyaxon run -p project1 -f file.yaml Run with updated params \b $ polyaxon run -p project1 -f file.yaml -P param1=234.2 -P param2=relu If a python file contains a component main, you can run that component \b polyaxon run -pm path/to/my-component.py If a python file contains more than one component, you can specify the component to run \b polyaxon run -pm path/to/my-component.py:componentA """ git_init = None if git_preset: # Check that the current path was initialized if not GitConfigManager.is_initialized(): Printer.print_error( "You can't use --git-init, " "the current path is not initialized with a valid git connection or a git url, " "please run `polyaxon init [--git-connection] [--git-url]` " "to set a valid git configuration.") sys.exit(1) git_init = GitConfigManager.get_config() if git_revision: git_init.git.revision = git_revision elif code_reference.is_git_initialized(path="."): if code_reference.is_dirty(path="."): Printer.print_warning( "Polyaxon detected uncommitted changes in the current git repo!" ) commit_hash = code_reference.get_commit() git_init.git.revision = commit_hash else: Printer.print_warning( "Polyaxon could not find a valid git repo, " "and will not add the current commit to the git initializer.") presets = validate_tags(presets) op_spec = check_polyaxonfile( polyaxonfile=polyaxonfile, python_module=python_module, url=url, hub=hub, params=params, presets=presets, queue=queue, nocache=nocache, verbose=False, eager=eager, git_init=git_init, ignore_template=ignore_template, ) if ignore_template: op_spec.disable_template() if op_spec.is_template(): click.echo( "Please customize the specification or disable the template.") sys.exit(1) owner, project_name = get_project_or_local(project, is_cli=True) tags = validate_tags(tags) if local: try: compiled_operation = OperationSpecification.compile_operation( op_spec) compiled_operation = CompiledOperationSpecification.apply_operation_contexts( compiled_operation) except (PolyaxonSchemaError, ValidationError): Printer.print_error( "Could not run this polyaxonfile locally, " "a context is required to resolve it dependencies.") sys.exit(1) docker_run( ctx=ctx, name=name, owner=owner, project_name=project_name, description=description, tags=tags, compiled_operation=compiled_operation, log=log, ) elif settings.CLIENT_CONFIG.no_api: k8s_run( ctx=ctx, name=name, owner=owner, project_name=project_name, description=description, tags=tags, op_spec=op_spec, log=log, ) else: platform_run( ctx=ctx, name=name, owner=owner, project_name=project_name, description=description, tags=tags, op_spec=op_spec, log=log, watch=watch, eager=eager, )
def init(project, polyaxonfile, purge): """Initialize a new polyaxonfile specification.""" owner, project_name = get_project_or_local(project, is_cli=True) try: polyaxon_client = PolyaxonClient() project_config = polyaxon_client.projects_v1.get_project( owner, project_name) except (ApiException, HTTPError) as e: Printer.print_error( "Make sure you have a project with this name `{}`".format(project)) handle_cli_error( e, message="You can a create new project with this command: " "polyaxon project create " "--name={} [--description=...] [--tags=...]".format(project_name), ) sys.exit(1) if purge: ProjectManager.purge() IgnoreManager.purge() init_project = False if ProjectManager.is_initialized(): local_project = ProjectManager.get_config() click.echo( "Warning! This project is already initialized with the following project:" ) with indentation.indent(4): indentation.puts("User: {}".format(local_project.user)) indentation.puts("Project: {}".format(local_project.name)) if click.confirm("Would you like to override this current config?", default=False): init_project = True else: init_project = True if init_project: ProjectManager.purge() config = polyaxon_client.sanitize_for_serialization(project_config) ProjectManager.set_config(config, init=True) Printer.print_success("Project was initialized") else: Printer.print_header("Project config was not changed.") init_ignore = False if IgnoreManager.is_initialized(): click.echo("Warning! Found a .polyaxonignore file.") if click.confirm("Would you like to override it?", default=False): init_ignore = True else: init_ignore = True if init_ignore: IgnoreManager.init_config() Printer.print_success("New .polyaxonignore file was created.") else: Printer.print_header(".polyaxonignore file was not changed.") if polyaxonfile: create_polyaxonfile() create_debug_polyaxonfile()
def test_get_project_or_local(self): with self.assertRaises(PolyaxonClientException): get_project_or_local(None) assert get_project_or_local("owner.project") == ("owner", "project")