Skip to content

Commit 1e56fc4

Browse files
committed
refactor: ♻️ Functionalize outdated check
1 parent 1a46c90 commit 1e56fc4

File tree

2 files changed

+53
-27
lines changed

2 files changed

+53
-27
lines changed

tools/generate-help-strings.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import sys
88
from io import StringIO
9+
from operator import itemgetter
910

1011
from rich.console import Console
1112

@@ -35,6 +36,19 @@ def _capture_help(args: list[str]) -> str:
3536
sys.stdout = old_stdout
3637

3738

39+
def _is_outdated(check: tuple[str, list[str], str]) -> bool:
40+
"""Return True if the current help output differs from the stored constant."""
41+
_, args, current = check
42+
return _capture_help(args) != current
43+
44+
45+
def _find_outdated_checks(
46+
checks: list[tuple[str, list[str], str]],
47+
) -> list[tuple[str, list[str]]]:
48+
"""Return checks whose current help output differs from the stored constant."""
49+
return list(map(itemgetter(0, 1), filter(_is_outdated, checks)))
50+
51+
3852
def _as_constant_snippet(name: str, text: str) -> str:
3953
"""Return a copy-pasteable constant assignment for *text*."""
4054
lines = text.splitlines()
@@ -47,9 +61,7 @@ def _as_constant_snippet(name: str, text: str) -> str:
4761
("_HELP_PAGE", ["--help"], _HELP_PAGE),
4862
("_BUILD_HELP_PAGE", ["build", "--help"], _BUILD_HELP_PAGE),
4963
]
50-
changed = [
51-
(name, args) for name, args, current in checks if _capture_help(args) != current
52-
]
64+
changed = _find_outdated_checks(checks)
5365

5466
if not changed:
5567
print("No changes detected. All help-output constants are up to date.")

uv.lock

Lines changed: 38 additions & 24 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)