]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Add detect-include-cycle check to pre-commit. 18013/head
authorMarc Fehling <mafehling.git@gmail.com>
Mon, 20 Jan 2025 13:17:21 +0000 (14:17 +0100)
committerMarc Fehling <mafehling.git@gmail.com>
Fri, 24 Jan 2025 09:16:56 +0000 (10:16 +0100)
.github/workflows/pre-commit.yml
.pre-commit-config.yaml
contrib/utilities/detect_include_cycles.py

index 54f5539a0fe7a35f56207008a3768237eec10b0a..50a2aa6c006b85ec397772fd1318b5c2bedb1e86 100644 (file)
@@ -16,4 +16,5 @@ jobs:
     steps:
     - uses: actions/checkout@v4
     - uses: actions/setup-python@v5
+    - run:  python -m pip install networkx
     - uses: pre-commit/action@v3.0.1
index 0f656dc75c0eccb83a064e8599fcab11345d207f..0b0ab6d02461b1bfb7a9de00e40f71446e44f851 100755 (executable)
@@ -46,3 +46,10 @@ repos:
   hooks:
   - id: typos
     files: (?x) ^(doc|examples|include|source|tests)/
+- repo: local
+  hooks:
+  - id: detect-include-cycles
+    name: Detect '#include' cycles
+    entry: python contrib/utilities/detect_include_cycles.py
+    pass_filenames: false
+    language: system
index 0bc9baa7e8932fef8d72fd03e2230fe9655c0d7e..81838f2c0a57360bc74cb1c27e33460cbb0bb895 100644 (file)
 # other module partitions.
 #
 # Call this script via
-#   python3 detect_include_cycles.py include/deal.II/*/*.h
+#   python3 contrib/utilities/detect_include_cycles.py
 # from the top-level directory.
 
-import sys
+from glob import glob
 import networkx as nx
 
 
@@ -47,11 +47,13 @@ def add_includes_for_file(header_file_name, G) :
 
 
 
-# Take the list of call arguments, excluding the first that contains
-# the name of the executable (i.e., this program). For each, add the
-# includes as the edges of a directed graph.
+# Create a list of all header files in the include folder.
+filelist = glob("include/**/*.h", recursive=True)
+assert filelist, "Please call the script from the top-level directory."
+
+# For each header file, add the includes as the edges of a directed graph.
 G = nx.DiGraph()
-for header_file_name in sys.argv[1:] :
+for header_file_name in filelist :
     add_includes_for_file(header_file_name, G)
 
 # Then figure out whether there are cycles and if so, print them:

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.