def purge(cache_only): """Purge the global config values.""" if not cache_only: ClientConfigManager.purge() CliConfigManager.purge() AuthConfigManager.purge() ProjectConfigManager.purge() RunConfigManager.purge() IgnoreConfigManager.purge() GitConfigManager.purge() Printer.print_success("Configs was removed.")
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 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, )