diff options
author | Mike Frysinger <vapier@google.com> | 2025-04-22 14:10:52 -0400 |
---|---|---|
committer | LUCI <gerrit-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2025-04-28 10:24:33 -0700 |
commit | 21cbcc54e99db175619959a5b185bbb4d9b81d5a (patch) | |
tree | f348d94fcfd29514a2ecdb1e50a3e4ff3e539e8f /release/update_manpages.py | |
parent | 0f200bb3a1dedafdc435a86f0308f22469b4e404 (diff) | |
download | git-repo-21cbcc54e99db175619959a5b185bbb4d9b81d5a.tar.gz |
update-manpages: include in unittests
People often forget to regen when making interface changes.
We skip the test if help2man isn't installed since it's not common,
and it's not available on our CI bots currently.
Change-Id: Ib4911a0e3fa1294ad90e4ac8afc047a0b7c2b66d
Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/469741
Tested-by: Mike Frysinger <vapier@google.com>
Reviewed-by: Gavin Mak <gavinmak@google.com>
Commit-Queue: Mike Frysinger <vapier@google.com>
Diffstat (limited to 'release/update_manpages.py')
-rw-r--r-- | release/update_manpages.py | 35 |
1 files changed, 31 insertions, 4 deletions
diff --git a/release/update_manpages.py b/release/update_manpages.py index 489de357..9ada83ff 100644 --- a/release/update_manpages.py +++ b/release/update_manpages.py | |||
@@ -27,9 +27,11 @@ import shutil | |||
27 | import subprocess | 27 | import subprocess |
28 | import sys | 28 | import sys |
29 | import tempfile | 29 | import tempfile |
30 | from typing import List | ||
30 | 31 | ||
31 | 32 | ||
32 | TOPDIR = Path(__file__).resolve().parent.parent | 33 | THIS_FILE = Path(__file__).resolve() |
34 | TOPDIR = THIS_FILE.parent.parent | ||
33 | MANDIR = TOPDIR.joinpath("man") | 35 | MANDIR = TOPDIR.joinpath("man") |
34 | 36 | ||
35 | # Load repo local modules. | 37 | # Load repo local modules. |
@@ -42,9 +44,23 @@ def worker(cmd, **kwargs): | |||
42 | subprocess.run(cmd, **kwargs) | 44 | subprocess.run(cmd, **kwargs) |
43 | 45 | ||
44 | 46 | ||
45 | def main(argv): | 47 | def get_parser() -> argparse.ArgumentParser: |
48 | """Get argument parser.""" | ||
46 | parser = argparse.ArgumentParser(description=__doc__) | 49 | parser = argparse.ArgumentParser(description=__doc__) |
47 | parser.parse_args(argv) | 50 | parser.add_argument( |
51 | "-n", | ||
52 | "--check", | ||
53 | "--dry-run", | ||
54 | action="store_const", | ||
55 | const=True, | ||
56 | help="Check if changes are necessary; don't actually change files", | ||
57 | ) | ||
58 | return parser | ||
59 | |||
60 | |||
61 | def main(argv: List[str]) -> int: | ||
62 | parser = get_parser() | ||
63 | opts = parser.parse_args(argv) | ||
48 | 64 | ||
49 | if not shutil.which("help2man"): | 65 | if not shutil.which("help2man"): |
50 | sys.exit("Please install help2man to continue.") | 66 | sys.exit("Please install help2man to continue.") |
@@ -117,6 +133,7 @@ def main(argv): | |||
117 | functools.partial(worker, cwd=tempdir, check=True), cmdlist | 133 | functools.partial(worker, cwd=tempdir, check=True), cmdlist |
118 | ) | 134 | ) |
119 | 135 | ||
136 | ret = 0 | ||
120 | for tmp_path in MANDIR.glob("*.1.tmp"): | 137 | for tmp_path in MANDIR.glob("*.1.tmp"): |
121 | path = tmp_path.parent / tmp_path.stem | 138 | path = tmp_path.parent / tmp_path.stem |
122 | old_data = path.read_text() if path.exists() else "" | 139 | old_data = path.read_text() if path.exists() else "" |
@@ -133,7 +150,17 @@ def main(argv): | |||
133 | ) | 150 | ) |
134 | new_data = re.sub(r'^(\.TH REPO "1" ")([^"]+)', r"\1", data, flags=re.M) | 151 | new_data = re.sub(r'^(\.TH REPO "1" ")([^"]+)', r"\1", data, flags=re.M) |
135 | if old_data != new_data: | 152 | if old_data != new_data: |
136 | path.write_text(data) | 153 | if opts.check: |
154 | ret = 1 | ||
155 | print( | ||
156 | f"{THIS_FILE.name}: {path.name}: " | ||
157 | "man page needs regenerating", | ||
158 | file=sys.stderr, | ||
159 | ) | ||
160 | else: | ||
161 | path.write_text(data) | ||
162 | |||
163 | return ret | ||
137 | 164 | ||
138 | 165 | ||
139 | def replace_regex(data): | 166 | def replace_regex(data): |