Skip to content

Commit 71a0152

Browse files
committed
Modernize tag release script.
1 parent 38e6ca9 commit 71a0152

1 file changed

Lines changed: 11 additions & 7 deletions

File tree

scripts/tag_release.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/usr/bin/env python3
2+
"""Automate tagged releases of this project."""
23
from __future__ import annotations
34

45
import argparse
@@ -8,7 +9,8 @@
89
import subprocess
910
import sys
1011
from pathlib import Path
11-
from typing import Tuple
12+
13+
# ruff: noqa: INP001, S603, S607
1214

1315
PROJECT_DIR = Path(__file__).parent.parent
1416

@@ -23,7 +25,7 @@
2325
parser.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

4749
def 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

6467
def 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

8690
if __name__ == "__main__":

0 commit comments

Comments
 (0)