Skip to content

Commit 22ea596

Browse files
etc: add script for detecting man sections that aren't included in the doc
1 parent e138d33 commit 22ea596

1 file changed

Lines changed: 47 additions & 0 deletions

File tree

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/usr/bin/env python3
2+
3+
4+
import sys
5+
import re
6+
from pathlib import Path, PosixPath
7+
8+
9+
def is_in_xml_comment(s: str, pos: int) -> bool:
10+
last_open = s.rfind("<!--", 0, pos)
11+
last_close = s.rfind("-->", 0, pos)
12+
return last_open != -1 and last_open > last_close
13+
14+
15+
def extract(path: PosixPath, pattern: re.Pattern) -> dict:
16+
result = dict()
17+
content = path.read_text(errors="ignore")
18+
for i, line in enumerate(content.splitlines(), 1):
19+
match = pattern.search(line)
20+
if match:
21+
result[match.group(1)] = f"{path}:{i}"
22+
return result
23+
24+
25+
def main() -> int:
26+
labels, includes = dict(), dict()
27+
label_pattern = re.compile(r'<#GAPDoc\s+Label\s*=\s*"(\w+)">')
28+
include_pattern = re.compile(r'<#Include\s+Label\s*=\s*"(\w+)"')
29+
for path in sorted(Path("doc/").glob("*.xml")):
30+
if not path.name.startswith("_"):
31+
labels |= extract(path, label_pattern)
32+
includes |= extract(path, include_pattern)
33+
34+
first_print = True
35+
for label, loc in labels.items():
36+
if label not in includes:
37+
if first_print:
38+
first_print = False
39+
print(
40+
"The following labels were found without a corresponding include:"
41+
)
42+
print(f"{loc}: {label}")
43+
44+
45+
if __name__ == "__main__":
46+
main()
47+
sys.exit(0)

0 commit comments

Comments
 (0)