Skip to contentSkip to conversation

Add pre-commit support

PATCH In review Antonin Godard 2 participants 5 messages Jul 3

lore
Share & tools
lore
#0 lore raw

v2 cover Add pre-commit support

---
Changes in v2:
- Patch 2/3: apply default path suggestion from Quentin (thanks!)
- Link to v1: https://patch.msgid.link/[email protected]

---
Antonin Godard (3):
tools/check-glossaries: return 1 in case of failure tools/check-glossaries: fix default doc path Add a pre-commit hook to check the glossaries

 .pre-commit-config.yaml              |  8 ++++++++
 documentation/README                 | 10 ++++++++++
 documentation/tools/check-glossaries | 10 ++++++++--
 3 files changed, 26 insertions(+), 2 deletions(-)

---
base-commit: def10b40398732ff73f23bf9cb8c0288a8ad7640
change-id: 20260702-pre-commit-fe4d1ca7bbc4

#1 lore raw

PATCH v2 1/3 tools/check-glossaries: return 1 in case of failure

Exit with 1 in case there's an issue with the glossaries. This will be used for pre-commit support.

---
 documentation/tools/check-glossaries | 7 +++++++
 1 file changed, 7 insertions(+)
documentation/tools/check-glossaries +7 -0
index b5dfe834e..9f1a47126 100755
@@ -4,6 +4,7 @@ import argparse
 import difflib
 import os
 import re
+import sys
 
 from pathlib import Path
 
@@ -33,6 +34,7 @@ def main():
     # :term:`A <ABIEXTENSION>` :term:`B` :term:`C <CACHE>`
     glossary_re = re.compile(r":term:`(?P<letter>[A-Z]{1})( <(?P<varname>[A-Z_]+)>)?`")
     entry_re = re.compile(r"^   :term:`(?P<entry>.+)`\s*$")
+    exit_code = 0
 
     for rst in glossaries:
 
@@ -74,6 +76,7 @@ def main():
         if diffs:
             print(f"WARNING: {rst}: entries are not properly sorted:")
             print('\n'.join(diffs))
+            exit_code = 1
 
         for letter in glossary:
             try:
@@ -81,9 +84,13 @@ def main():
             except ValueError:
                 print(f"WARNING: {rst}: variable "
                       f"{glossary[letter]} in glossary does not exist")
+                exit_code = 1
             if index > 0 and entries[index - 1].startswith(letter[0]):
                 print(f"WARNING: {rst}: The variable {glossary[letter]} shouldn't be in "
                      "the glossary.")
+                exit_code = 1
+
+    sys.exit(exit_code)
 
 
 if __name__ == "__main__":
Signature · 1 line
2.54.0
#2 lore raw

PATCH v2 2/3 tools/check-glossaries: fix default doc path

In reply to Antonin Godard

This default path pointing to the documentation was wrong, fix it.

---
 documentation/tools/check-glossaries | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
documentation/tools/check-glossaries +1 -2
index 9f1a47126..da4987ff3 100755
@@ -2,7 +2,6 @@
 
 import argparse
 import difflib
-import os
 import re
 import sys
 
@@ -14,7 +13,7 @@ def parse_arguments() -> argparse.Namespace:
 
     parser.add_argument("-d", "--docs-dir",
                         type=Path,
-                        default=Path(os.path.dirname(os.path.realpath(__file__))) / "documentation",
+                        default=Path(__file__).resolve().parent.parent,
                         help="Path to documentation/ directory in yocto-docs")
 
     return parser.parse_args()
Signature · 1 line
2.54.0
Reviewed-by on v2 2/3
#3 lore raw

Re: [docs] [PATCH v2 2/3] tools/check-glossaries: fix default doc path

Hi Antonin,

Quoted 2 lines · Antonin Godard via lists.yoctoproject.org

This default path pointing to the documentation was wrong, fix it.

Thanks!
Quentin

#4 lore raw

PATCH v2 3/3 Add a pre-commit hook to check the glossaries

In reply to Antonin Godard

It is easy to badly order the glossaries or forget to update the list at the beginning of the variables.rst file. Add a pre-commit hook that does it for us, and update the README to mention to enable it.

---
 .pre-commit-config.yaml |  8 ++++++++
 documentation/README    | 10 ++++++++++
 2 files changed, 18 insertions(+)
.pre-commit-config.yaml new file +8 -0
new file mode 100644
index 000000000..f2b73a481
@@ -0,0 +1,8 @@
+repos:
+  - repo: local
+    hooks:
+      - id: check-glossaries
+        name: Check glossaries alphabetical order
+        entry: ./documentation/tools/check-glossaries
+        language: python
+        pass_filenames: false
documentation/README +10 -0
index 7c4472c73..326930932 100644
@@ -89,6 +89,16 @@ generated with DocBook.
 How to build the Yocto Project documentation
 ============================================
 
+If possible, install pre-commit hooks to make sure you did not miss any
+updates that are run automatically:
+
+  $ pre-commit install
+
+The pre-commit project can be installed on your host using your package manager,
+usually under the name "pre-commit", e.g.:
+
+  $ sudo apt-get install pre-commit
+
 To build the documentation, you need Sphinx and a few other packages,
 which depend on your host GNU/Linux distribution. Such packages are listed on
 https://docs.yoctoproject.org/dev/ref-manual/system-requirements.html#required-packages-for-the-build-host
Signature · 1 line
2.54.0