[docs]defpublish_distributions(tag:str,hvcs_client:RemoteHvcsBase,dist_glob_patterns:tuple[str,...],noop:bool=False,)->None:ifnoop:noop_report(str.join(" ",["would have uploaded files matching any of the globs",str.join(", ",[repr(g)forgindist_glob_patterns]),"to a remote VCS release, if supported",],))returnlog.info("Uploading distributions to release")forpatternindist_glob_patterns:hvcs_client.upload_dists(tag=tag,dist_glob=pattern)# type: ignore[attr-defined]
@click.command(short_help="Publish distributions to VCS Releases",context_settings={"help_option_names":["-h","--help"],},)@click.option("--tag","tag",help="The tag associated with the release to publish to",default="latest",)@click.pass_objdefpublish(cli_ctx:CliContextObj,tag:str)->None:"""Build and publish a distribution to a VCS release."""ctx=click.get_current_context()runtime=cli_ctx.runtime_ctxhvcs_client=runtime.hvcs_clienttranslator=runtime.version_translatordist_glob_patterns=runtime.dist_glob_patternswithRepo(str(runtime.repo_dir))asgit_repo:repo_tags=git_repo.tagsiftag=="latest":try:tag=str(tags_and_versions(repo_tags,translator)[0][0])exceptIndexError:click.echo(str.join(" ",["No tags found with format",repr(translator.tag_format),"couldn't identify latest version",],),err=True,)ctx.exit(1)iftagnotin{tag.namefortaginrepo_tags}:click.echo(f"Tag '{tag}' not found in local repository!",err=True)ctx.exit(1)ifnotisinstance(hvcs_client,RemoteHvcsBase):click.echo("Remote does not support artifact upload. Exiting with no action taken...",err=True,)returnpublish_distributions(tag=tag,hvcs_client=hvcs_client,dist_glob_patterns=dist_glob_patterns,noop=runtime.global_cli_options.noop,)