]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Indent Python scripts. 18491/head
authorWolfgang Bangerth <bangerth@colostate.edu>
Tue, 27 May 2025 14:59:35 +0000 (08:59 -0600)
committerWolfgang Bangerth <bangerth@colostate.edu>
Tue, 27 May 2025 14:59:35 +0000 (08:59 -0600)
contrib/utilities/detect_module_cycles.py
contrib/utilities/find_module_partition_dependencies.py

index 620203d9db36d3bdd5120d6499c72d22a450c1e4..a427fe787d88ee95e52f199d5799f6ff207f613e 100644 (file)
@@ -35,26 +35,24 @@ match_exports = re.compile(r"export module dealii *: *(.*);")
 # For a given .cc file, read through all the lines and extract the
 # ones that correspond to export or import statements. For those, add
 # a link to the graph.
-def add_imports_for_file(interface_module_partition_file, G) :
+def add_imports_for_file(interface_module_partition_file, G):
     f = open(interface_module_partition_file)
     lines = f.readlines()
     f.close()
-    
-    for line in lines :
+
+    for line in lines:
         m = match_exports.match(line)
-        if m :
+        if m:
             module_partition = m.group(1)
             # There can only be one 'export' statement per file, so
             # stop reading:
             break
 
-    for line in lines :
+    for line in lines:
         m = match_imports.match(line)
-        if m :
+        if m:
             imported_partition = m.group(1)
-            G.add_edge(module_partition,
-                       imported_partition)
-
+            G.add_edge(module_partition, imported_partition)
 
 
 # Create a list of all source files in the build folder
@@ -63,14 +61,14 @@ assert filelist, "Please call the script from the top-level directory."
 
 # For each header file, add the imports as the edges of a directed graph.
 G = nx.DiGraph()
-for interface_module_partition_file in filelist :
+for interface_module_partition_file in filelist:
     add_imports_for_file(interface_module_partition_file, G)
 
 # Then figure out whether there are cycles and if so, print them:
 cycles = nx.simple_cycles(G)
 cycles_as_list = list(cycles)
-if (len(cycles_as_list) > 0) :
-    print (f"Cycles in the module partition graph detected!")
-    for cycle in cycles_as_list :
+if len(cycles_as_list) > 0:
+    print(f"Cycles in the module partition graph detected!")
+    for cycle in cycles_as_list:
         print(cycle)
     exit(1)
index 6bdad6b65a655787769b5c966280917818ddc7d6..873a0bc7b23dfd3da5e355d2b0c0770e07c93ca6 100644 (file)
@@ -42,30 +42,30 @@ match_exports = re.compile(r"(export )?module dealii *: *(.*);")
 # For a given source file, read through all the lines and extract the
 # ones that correspond to export or import statements. For those, add
 # a link to the graph.
-def add_imports_for_file(module_partition_file, G) :
+def add_imports_for_file(module_partition_file, G):
     f = open(module_partition_file)
     lines = f.readlines()
     f.close()
 
     module_partition = ""
-    for line in lines :
+    for line in lines:
         m = match_exports.match(line)
-        if m :
+        if m:
             module_partition = m.group(2)
             # There can only be one 'export' statement per file, so
             # stop reading after recording the mapping from partition
             # name to file name:
             partition_to_filename[module_partition] = module_partition_file
             break
-    assert module_partition != "", f"File <{module_partition_file} does not seem to export a module partition!"
+    assert (
+        module_partition != ""
+    ), f"File <{module_partition_file} does not seem to export a module partition!"
 
-    for line in lines :
+    for line in lines:
         m = match_imports.match(line)
-        if m :
+        if m:
             imported_partition = m.group(2)
-            G.add_edge(module_partition,
-                       imported_partition)
-
+            G.add_edge(module_partition, imported_partition)
 
 
 # Create a list of all source files in the build folder
@@ -76,22 +76,27 @@ assert filelist, "Please call the script from the top-level build directory."
 # For each header file, add the imports as the edges of a directed graph.
 G = nx.DiGraph()
 G.add_node(module_partition_name)  # Make sure the graph has at least one node
-for module_partition_file in filelist :
+for module_partition_file in filelist:
     add_imports_for_file(module_partition_file, G)
 
-assert module_partition_name in partition_to_filename, \
-    "The module partition given as argument could not be found in the module units found"
-    
+assert (
+    module_partition_name in partition_to_filename
+), "The module partition given as argument could not be found in the module units found"
+
 
 # Now find everything that is upstream of the module partition
 # specified on the command line:
 print(f"The dependencies of module partition '{module_partition_name}' are:")
-for node in nx.dfs_postorder_nodes(G, source=module_partition_name) :
-    if node != module_partition_name :
-        if node in partition_to_filename :
+for node in nx.dfs_postorder_nodes(G, source=module_partition_name):
+    if node != module_partition_name:
+        if node in partition_to_filename:
             print(f"  {node}, implemented in {partition_to_filename[node]}")
-        else :
+        else:
             print(f"  {node}, implemented in unknown file")
 
-n_dependencies = sum(1 for _ in nx.dfs_postorder_nodes(G, source=module_partition_name))-1
-print(f"{n_dependencies} partitions are upstream dependencies for '{module_partition_name}'")
+n_dependencies = (
+    sum(1 for _ in nx.dfs_postorder_nodes(G, source=module_partition_name)) - 1
+)
+print(
+    f"{n_dependencies} partitions are upstream dependencies for '{module_partition_name}'"
+)

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.