22import json
33import pathlib
44
5- class Trie :
65
6+ class Trie :
77 def __init__ (self ):
88 self .children = {}
99 self .values = []
@@ -37,13 +37,12 @@ def tabulator(self):
3737 children = v .tabulator ()
3838 feature = k
3939 if v .entry != "" :
40- link = "<a href='%s' target='_blank'><i class='fa-solid fa-link' aria-label='link'></i></a>" % v .entry
40+ link = (
41+ "<a href='%s' target='_blank'><i class='fa-solid fa-link' aria-label='link'></i></a>"
42+ % v .entry
43+ )
4144 feature = "%s %s" % (link , k )
42- d = {
43- "sort_key" : k ,
44- "feature" : feature ,
45- ** v .tabulator_leaf ()
46- }
45+ d = {"sort_key" : k , "feature" : feature , ** v .tabulator_leaf ()}
4746 if children :
4847 d ["_children" ] = children
4948 result .append (d )
@@ -60,13 +59,14 @@ def size(self):
6059 return 1
6160 return sum ([v .size () for v in self .children .values ()])
6261
63- def walk (self , visitor , path = None ):
62+ def walk (self , visitor , path = None ):
6463 if path is None :
6564 path = []
6665 visitor (self , path )
6766 for k , v in self .children .items ():
6867 v .walk (visitor , path + [k ])
6968
69+
7070def extract_metadata_from_file (file ):
7171 with open (file , "r" ) as f :
7272 lines = f .readlines ()
@@ -78,10 +78,13 @@ def extract_metadata_from_file(file):
7878 start = i
7979 else :
8080 end = i
81- metadata = yaml .load ("" .join (lines [start + 1 :end ]), Loader = yaml .SafeLoader )
81+ metadata = yaml .load (
82+ "" .join (lines [start + 1 : end ]), Loader = yaml .SafeLoader
83+ )
8284 return metadata
8385 raise ValueError ("No metadata found in file %s" % file )
8486
87+
8588def table_cell (entry , _feature , _format_name , format_config ):
8689 if type (format_config ) == str :
8790 format_config = {}
@@ -90,8 +93,22 @@ def table_cell(entry, _feature, _format_name, format_config):
9093 if quality is not None :
9194 if type (quality ) == str :
9295 quality = quality .lower ()
93- qualities = {- 1 : "🚫" , 0 : "⚠" , 1 : "✓" , 2 : "✓✓" , "unknown" : "❓" , "na" : "NA" }
94- colors = {- 1 : "bad" , 0 : "ok" , 1 : "good" , 2 : "good" , "unknown" : "unknown" , "na" : "na" }
96+ qualities = {
97+ - 1 : "🚫" ,
98+ 0 : "⚠" ,
99+ 1 : "✓" ,
100+ 2 : "✓✓" ,
101+ "unknown" : "❓" ,
102+ "na" : "NA" ,
103+ }
104+ colors = {
105+ - 1 : "bad" ,
106+ 0 : "ok" ,
107+ 1 : "good" ,
108+ 2 : "good" ,
109+ "unknown" : "unknown" ,
110+ "na" : "na" ,
111+ }
95112 color = colors [quality ]
96113 quality_icon = qualities .get (quality , "❓" )
97114 result .append (f"<span class='{ color } '>{ quality_icon } </span>" )
@@ -101,7 +118,8 @@ def table_cell(entry, _feature, _format_name, format_config):
101118 result .append (f"<span title='{ comment } '>💬</span>" )
102119 return "" .join (result )
103120
104- def compute_trie (detailed = False ):
121+
122+ def compute_trie (detailed = False ):
105123 trie = Trie ()
106124 pattern = "qmd-files/**/*.qmd" if detailed else "qmd-files/**/document.qmd"
107125 for entry in pathlib .Path ("." ).glob (pattern ):
@@ -115,26 +133,37 @@ def compute_trie(detailed = False):
115133 except KeyError :
116134 raise Exception ("No format found in %s" % entry )
117135 for format_name , format_config in format .items ():
118- trie .insert (feature , {
119- "feature" : "/" .join (feature ),
120- "format" : format_name ,
121- "entry" : entry ,
122- "format_config" : format_config ,
123- "table_cell" : table_cell (entry , feature , format_name , format_config )
124- })
136+ trie .insert (
137+ feature ,
138+ {
139+ "feature" : "/" .join (feature ),
140+ "format" : format_name ,
141+ "entry" : entry ,
142+ "format_config" : format_config ,
143+ "table_cell" : table_cell (
144+ entry , feature , format_name , format_config
145+ ),
146+ },
147+ )
125148 return trie
126149
127- def render_features_formats_data (trie = None ):
150+
151+ def render_features_formats_data (trie = None ):
128152 if trie is None :
129153 trie = compute_trie ()
130154 entries = trie .tabulator ()
131- return "```{=html}\n <script type='text/javascript'>\n var tableData = %s;\n </script>\n ```\n " % json .dumps (entries , indent = 2 )
155+ return (
156+ "```{=html}\n <script type='text/javascript'>\n var tableData = %s;\n </script>\n ```\n "
157+ % json .dumps (entries , indent = 2 )
158+ )
159+
132160
133- def compute_quality_summary (trie = None ):
161+ def compute_quality_summary (trie = None ):
134162 if trie is None :
135163 trie = compute_trie ()
136164 quality_summary = {"unknown" : 0 , - 1 : 0 , 0 : 0 , 1 : 0 , 2 : 0 , "na" : 0 }
137165 n_rows = 0
166+
138167 def visit (node , _path ):
139168 nonlocal n_rows
140169 if not node .children or len (node .values ):
@@ -149,5 +178,6 @@ def visit(node, _path):
149178 if quality_summary .get (quality ) is None :
150179 raise ValueError ("Invalid quality value %s" % quality )
151180 quality_summary [quality ] += 1
181+
152182 trie .walk (visit )
153- return {"n_rows" : n_rows , "quality" : quality_summary }
183+ return {"n_rows" : n_rows , "quality" : quality_summary }
0 commit comments