diff options
author | Antonin Godard <antonin.godard@bootlin.com> | 2025-07-29 13:30:02 +0200 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2025-08-08 23:41:11 +0100 |
commit | dc768a3d9d6df0cd048bf7ded4773372929f1675 (patch) | |
tree | 307e48ca1d172946f4962b0e2d0e35d4ae8efbea /documentation | |
parent | 6217bbbe7e030fed93c302fd9826e7bb73a217ce (diff) | |
download | poky-dc768a3d9d6df0cd048bf7ded4773372929f1675.tar.gz |
Add a script to validate documentation glossaries
Instead of tracking the glossary manually, add a small script that
checks if it is properly sorted.
Add two comments between the start and end of the glossary for the
script to know where it's located.
The script also checks if the variables are properly sorted. It uses
difflib and returns the diff if there's a difference between the
unsorted and sorted list.
Messages beginning with "WARNING:" are reported by the Autobuilder,
which is the reason for this format.
(From yocto-docs rev: 416d50c0c322eb88bf13353a198db7211e4d665a)
Signed-off-by: Antonin Godard <antonin.godard@bootlin.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'documentation')
-rw-r--r-- | documentation/ref-manual/variables.rst | 6 | ||||
-rwxr-xr-x | documentation/tools/check-glossaries | 90 |
2 files changed, 96 insertions, 0 deletions
diff --git a/documentation/ref-manual/variables.rst b/documentation/ref-manual/variables.rst index e4d5a9c97a..6c2344950b 100644 --- a/documentation/ref-manual/variables.rst +++ b/documentation/ref-manual/variables.rst | |||
@@ -7,6 +7,9 @@ Variables Glossary | |||
7 | This chapter lists common variables used in the OpenEmbedded build | 7 | This chapter lists common variables used in the OpenEmbedded build |
8 | system and gives an overview of their function and contents. | 8 | system and gives an overview of their function and contents. |
9 | 9 | ||
10 | .. | ||
11 | check_glossary_begin | ||
12 | |||
10 | :term:`A <ABIEXTENSION>` :term:`B` :term:`C <CACHE>` | 13 | :term:`A <ABIEXTENSION>` :term:`B` :term:`C <CACHE>` |
11 | :term:`D` :term:`E <EFI_PROVIDER>` :term:`F <FAKEROOT>` | 14 | :term:`D` :term:`E <EFI_PROVIDER>` :term:`F <FAKEROOT>` |
12 | :term:`G <GCCPIE>` :term:`H <HGDIR>` :term:`I <IMAGE_BASENAME>` | 15 | :term:`G <GCCPIE>` :term:`H <HGDIR>` :term:`I <IMAGE_BASENAME>` |
@@ -16,6 +19,9 @@ system and gives an overview of their function and contents. | |||
16 | :term:`U <UBOOT_BINARY>` :term:`V <VIRTUAL-RUNTIME>` | 19 | :term:`U <UBOOT_BINARY>` :term:`V <VIRTUAL-RUNTIME>` |
17 | :term:`W <WARN_QA>` :term:`X <XSERVER>` :term:`Z <ZSTD_THREADS>` | 20 | :term:`W <WARN_QA>` :term:`X <XSERVER>` :term:`Z <ZSTD_THREADS>` |
18 | 21 | ||
22 | .. | ||
23 | check_glossary_end | ||
24 | |||
19 | .. glossary:: | 25 | .. glossary:: |
20 | :sorted: | 26 | :sorted: |
21 | 27 | ||
diff --git a/documentation/tools/check-glossaries b/documentation/tools/check-glossaries new file mode 100755 index 0000000000..b5dfe834e5 --- /dev/null +++ b/documentation/tools/check-glossaries | |||
@@ -0,0 +1,90 @@ | |||
1 | #!/usr/bin/env python3 | ||
2 | |||
3 | import argparse | ||
4 | import difflib | ||
5 | import os | ||
6 | import re | ||
7 | |||
8 | from pathlib import Path | ||
9 | |||
10 | |||
11 | def parse_arguments() -> argparse.Namespace: | ||
12 | parser = argparse.ArgumentParser(description="Print supported distributions") | ||
13 | |||
14 | parser.add_argument("-d", "--docs-dir", | ||
15 | type=Path, | ||
16 | default=Path(os.path.dirname(os.path.realpath(__file__))) / "documentation", | ||
17 | help="Path to documentation/ directory in yocto-docs") | ||
18 | |||
19 | return parser.parse_args() | ||
20 | |||
21 | |||
22 | glossaries = ( | ||
23 | 'ref-manual/variables.rst', | ||
24 | 'ref-manual/terms.rst', | ||
25 | ) | ||
26 | |||
27 | |||
28 | def main(): | ||
29 | |||
30 | args = parse_arguments() | ||
31 | in_glossary = False | ||
32 | # Pattern to match: | ||
33 | # :term:`A <ABIEXTENSION>` :term:`B` :term:`C <CACHE>` | ||
34 | glossary_re = re.compile(r":term:`(?P<letter>[A-Z]{1})( <(?P<varname>[A-Z_]+)>)?`") | ||
35 | entry_re = re.compile(r"^ :term:`(?P<entry>.+)`\s*$") | ||
36 | |||
37 | for rst in glossaries: | ||
38 | |||
39 | glossary = {} | ||
40 | rst_path = Path(args.docs_dir) / rst | ||
41 | |||
42 | with open(rst_path, "r") as f: | ||
43 | for line in f.readlines(): | ||
44 | if "check_glossary_begin" in line: | ||
45 | in_glossary = True | ||
46 | continue | ||
47 | if in_glossary: | ||
48 | for m in re.finditer(glossary_re, line.strip()): | ||
49 | letter = m.group("letter") | ||
50 | varname = m.group("varname") | ||
51 | if varname is None: | ||
52 | varname = letter | ||
53 | glossary[letter] = varname | ||
54 | if "check_glossary_end" in line: | ||
55 | in_glossary = False | ||
56 | break | ||
57 | |||
58 | entries = [] | ||
59 | |||
60 | with open(rst_path, "r") as f: | ||
61 | for line in f.readlines(): | ||
62 | m = re.match(entry_re, line) | ||
63 | if m: | ||
64 | entries.append(m.group("entry")) | ||
65 | |||
66 | # We lower here because underscore (_) come before lowercase letters | ||
67 | # (the natural way) but after uppercase letters (which is not natural) | ||
68 | sorted_entries = sorted(entries, key=lambda t: t.lower()) | ||
69 | diffs = list(difflib.unified_diff(entries, | ||
70 | sorted_entries, | ||
71 | fromfile="original_list", | ||
72 | tofile="sorted_list")) | ||
73 | |||
74 | if diffs: | ||
75 | print(f"WARNING: {rst}: entries are not properly sorted:") | ||
76 | print('\n'.join(diffs)) | ||
77 | |||
78 | for letter in glossary: | ||
79 | try: | ||
80 | index = entries.index(glossary[letter]) | ||
81 | except ValueError: | ||
82 | print(f"WARNING: {rst}: variable " | ||
83 | f"{glossary[letter]} in glossary does not exist") | ||
84 | if index > 0 and entries[index - 1].startswith(letter[0]): | ||
85 | print(f"WARNING: {rst}: The variable {glossary[letter]} shouldn't be in " | ||
86 | "the glossary.") | ||
87 | |||
88 | |||
89 | if __name__ == "__main__": | ||
90 | main() | ||