From aa3f142bb3e48ecf185107691cbc452991eb2988 Mon Sep 17 00:00:00 2001 From: bswck Date: Tue, 6 Aug 2024 00:28:35 +0200 Subject: [PATCH 1/7] Implement `coh tag` command Closes #6 --- __init__.py | 3 +++ __main__.py | 14 ++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/__init__.py b/__init__.py index 3872732..c8b05f9 100644 --- a/__init__.py +++ b/__init__.py @@ -1,5 +1,8 @@ __requires__ = [ 'coherent.build', 'coherent.test', + 'jaraco.vcs', + 'jaraco.versioning', 'typer', + 'typing-extensions', ] diff --git a/__main__.py b/__main__.py index 8587fff..716fb57 100644 --- a/__main__.py +++ b/__main__.py @@ -2,9 +2,12 @@ import runpy import subprocess import sys +from typing_extensions import Annotated import typer from coherent.build import bootstrap +from jaraco.vcs import repo +from jaraco.versioning import semver app = typer.Typer() @@ -35,5 +38,16 @@ def build() -> None: runpy.run_module('coherent.build', run_name='__main__') +@app.command(context_settings=dict(allow_extra_args=True)) +def tag( + tag_name: str, + context: typer.Context, + location: Annotated[str, typer.Option('-C', help='Path to repository.')] = '.', +) -> None: + if tag_name in ('major', 'minor', 'patch'): + tag_name = semver(repo(location).get_next_version(tag_name)) + subprocess.run(['git', '-C', location, 'tag', '-a', tag_name, *context.args]) + + if __name__ == '__main__': app() From 5e6d096fbc643ff6a118b03456c40979976e7da3 Mon Sep 17 00:00:00 2001 From: bswck Date: Tue, 6 Aug 2024 00:36:18 +0200 Subject: [PATCH 2/7] Use `Versioned.semantic_increment` to identify relative tag names --- __main__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/__main__.py b/__main__.py index 716fb57..3fc2555 100644 --- a/__main__.py +++ b/__main__.py @@ -7,7 +7,7 @@ import typer from coherent.build import bootstrap from jaraco.vcs import repo -from jaraco.versioning import semver +from jaraco.versioning import Versioned, semver app = typer.Typer() @@ -44,7 +44,7 @@ def tag( context: typer.Context, location: Annotated[str, typer.Option('-C', help='Path to repository.')] = '.', ) -> None: - if tag_name in ('major', 'minor', 'patch'): + if tag_name in Versioned.semantic_increment: tag_name = semver(repo(location).get_next_version(tag_name)) subprocess.run(['git', '-C', location, 'tag', '-a', tag_name, *context.args]) From 066882b9bcded2a80a6857d69220646b9a29fcc2 Mon Sep 17 00:00:00 2001 From: bswck Date: Tue, 6 Aug 2024 19:01:56 +0200 Subject: [PATCH 3/7] Rename `tag_name` parameter to `kind_or_name` --- __main__.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/__main__.py b/__main__.py index 3fc2555..5981c0f 100644 --- a/__main__.py +++ b/__main__.py @@ -40,13 +40,15 @@ def build() -> None: @app.command(context_settings=dict(allow_extra_args=True)) def tag( - tag_name: str, + kind_or_name: str, context: typer.Context, location: Annotated[str, typer.Option('-C', help='Path to repository.')] = '.', ) -> None: - if tag_name in Versioned.semantic_increment: - tag_name = semver(repo(location).get_next_version(tag_name)) - subprocess.run(['git', '-C', location, 'tag', '-a', tag_name, *context.args]) + if kind_or_name in Versioned.semantic_increment: + name = semver(repo(location).get_next_version(kind_or_name)) + else: + name = kind_or_name + subprocess.run(['git', '-C', location, 'tag', '-a', name, *context.args]) if __name__ == '__main__': From 53848f1137e26d0c110bfc1aa879d39fb6cc2e1f Mon Sep 17 00:00:00 2001 From: bswck Date: Tue, 6 Aug 2024 19:17:14 +0200 Subject: [PATCH 4/7] Accept `Repo` as a CLI argument --- __main__.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/__main__.py b/__main__.py index 5981c0f..315a7fb 100644 --- a/__main__.py +++ b/__main__.py @@ -6,7 +6,7 @@ import typer from coherent.build import bootstrap -from jaraco.vcs import repo +from jaraco.vcs import Repo from jaraco.versioning import Versioned, semver @@ -42,13 +42,23 @@ def build() -> None: def tag( kind_or_name: str, context: typer.Context, - location: Annotated[str, typer.Option('-C', help='Path to repository.')] = '.', + repository: Annotated[ + Repo, + typer.Option( + '-R', '--repository', + help='Path to repository.', + parser=Repo.detect, + ), + ] = '.', ) -> None: if kind_or_name in Versioned.semantic_increment: - name = semver(repo(location).get_next_version(kind_or_name)) + name = semver(repository.get_next_version(kind_or_name)) else: name = kind_or_name - subprocess.run(['git', '-C', location, 'tag', '-a', name, *context.args]) + subprocess.run([ + 'git', '-C', repository.location, 'tag', '-a', name, + '-m', '', *context.args] + ) if __name__ == '__main__': From ac522ac7ccb6122b2999bee81df9e2788641b77a Mon Sep 17 00:00:00 2001 From: bswck Date: Tue, 6 Aug 2024 19:19:31 +0200 Subject: [PATCH 5/7] Rearrange and call `semver()` on name unconditionally --- __main__.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/__main__.py b/__main__.py index 315a7fb..f060675 100644 --- a/__main__.py +++ b/__main__.py @@ -52,13 +52,11 @@ def tag( ] = '.', ) -> None: if kind_or_name in Versioned.semantic_increment: - name = semver(repository.get_next_version(kind_or_name)) + name = repository.get_next_version(kind_or_name) else: name = kind_or_name - subprocess.run([ - 'git', '-C', repository.location, 'tag', '-a', name, - '-m', '', *context.args] - ) + args = ['-a', semver(name), '-m', '', *context.args] + subprocess.run(['git', '-C', repository.location, 'tag', *args]) if __name__ == '__main__': From 00c36b9b8ce9c9ab21bd4391d274a26c6038681d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartosz=20S=C5=82awecki?= Date: Fri, 30 Aug 2024 22:37:49 +0200 Subject: [PATCH 6/7] Error on unsuccessful tag creation command execution --- __main__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/__main__.py b/__main__.py index f060675..c70fc84 100644 --- a/__main__.py +++ b/__main__.py @@ -56,7 +56,7 @@ def tag( else: name = kind_or_name args = ['-a', semver(name), '-m', '', *context.args] - subprocess.run(['git', '-C', repository.location, 'tag', *args]) + subprocess.run(['git', '-C', repository.location, 'tag', *args], check=True) if __name__ == '__main__': From 53f5cc9703ac243c8f9c771775c7bbde4a67ae15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartosz=20S=C5=82awecki?= Date: Fri, 30 Aug 2024 22:39:00 +0200 Subject: [PATCH 7/7] Log successful creation of a tag --- __main__.py | 1 + 1 file changed, 1 insertion(+) diff --git a/__main__.py b/__main__.py index c70fc84..4ed6812 100644 --- a/__main__.py +++ b/__main__.py @@ -57,6 +57,7 @@ def tag( name = kind_or_name args = ['-a', semver(name), '-m', '', *context.args] subprocess.run(['git', '-C', repository.location, 'tag', *args], check=True) + print(f"Created tag {name}") if __name__ == '__main__':