11#!/usr/bin/env python3
2+ """Automate tagged releases of this project."""
23from __future__ import annotations
34
45import argparse
89import subprocess
910import sys
1011from pathlib import Path
11- from typing import Tuple
12+
13+ # ruff: noqa: INP001, S603, S607
1214
1315PROJECT_DIR = Path (__file__ ).parent .parent
1416
2325parser .add_argument ("-v" , "--verbose" , action = "store_true" , help = "Print debug information." )
2426
2527
26- def parse_changelog (args : argparse .Namespace ) -> Tuple [str , str ]:
28+ def parse_changelog (args : argparse .Namespace ) -> tuple [str , str ]:
2729 """Return an updated changelog and and the list of changes."""
2830 match = re .match (
2931 pattern = r"(.*?## \[Unreleased]\n)(.+?\n)(\n*## \[.*)" ,
@@ -32,9 +34,9 @@ def parse_changelog(args: argparse.Namespace) -> Tuple[str, str]:
3234 )
3335 assert match
3436 header , changes , tail = match .groups ()
35- tagged = "\n ## [%s ] - %s \n %s" % (
37+ tagged = "\n ## [{} ] - {} \n {}" . format (
3638 args .tag ,
37- datetime .date .today ().isoformat (),
39+ datetime .date .today ().isoformat (), # Local timezone is fine, probably. # noqa: DTZ011
3840 changes ,
3941 )
4042 if args .verbose :
@@ -45,6 +47,7 @@ def parse_changelog(args: argparse.Namespace) -> Tuple[str, str]:
4547
4648
4749def replace_unreleased_tags (tag : str , dry_run : bool ) -> None :
50+ """Walk though sources and replace pending tags with the new tag."""
4851 match = re .match (r"\d+\.\d+" , tag )
4952 assert match
5053 short_tag = match .group ()
@@ -62,7 +65,8 @@ def replace_unreleased_tags(tag: str, dry_run: bool) -> None:
6265
6366
6467def main () -> None :
65- if len (sys .argv ) == 1 :
68+ """Entry function."""
69+ if len (sys .argv ) <= 1 :
6670 parser .print_help (sys .stderr )
6771 sys .exit (1 )
6872
@@ -79,8 +83,8 @@ def main() -> None:
7983 if not args .dry_run :
8084 (PROJECT_DIR / "CHANGELOG.md" ).write_text (new_changelog , encoding = "utf-8" )
8185 edit = ["-e" ] if args .edit else []
82- subprocess .check_call (["git" , "commit" , "-avm" , "Prepare %s release." % args . tag ] + edit )
83- subprocess .check_call (["git" , "tag" , args .tag , "-am" , "%s \n \n %s" % ( args . tag , changes )] + edit )
86+ subprocess .check_call (["git" , "commit" , "-avm" , f "Prepare { args . tag } release.", * edit ] )
87+ subprocess .check_call (["git" , "tag" , args .tag , "-am" , f" { args . tag } \n \n { changes } " , * edit ] )
8488
8589
8690if __name__ == "__main__" :
0 commit comments