2121}
2222
2323
24- @dataclass
25- class Notes :
26- description : str | None
27- table : str | None
28-
29-
3024@dataclass
3125class File :
3226 name : str
3327 description : str
3428 table : str
35- notes : Notes | None
29+ notes : str | None
3630
3731
3832@dataclass
@@ -61,17 +55,16 @@ def load_file(path: Path) -> File:
6155 data = yaml .safe_load (f )
6256
6357 try :
64- table , notes_table = fields2table (data ["fields" ])
58+ table = fields2table (data ["fields" ])
6559 except KeyError :
6660 print (f"MISSING VALUE IN { path } " )
6761 raise
6862
6963 name = f"{ path .stem } .csv"
70- title = add_full_stop (data ["title" ])
71- if desc := data .get ("description" , None ):
72- desc = add_full_stop (desc )
73- notes = Notes (desc , notes_table ) if desc or notes_table else None
74- return File (name , title , table , notes )
64+ desc = add_full_stop (data ["description" ])
65+ if note := data .get ("notes" , None ):
66+ note = add_full_stop (note )
67+ return File (name , desc , table , note )
7568
7669
7770def add_full_stop (s : str ) -> str :
@@ -84,28 +77,18 @@ def add_full_stop(s: str) -> str:
8477
8578def fields2table (fields : list [dict [str , str ]]) -> tuple [str , str | None ]:
8679 data = []
87- notes = []
8880 for f in fields :
89- row = {"Field" : f"`{ f ['name' ]} `" , "Description" : f ["title" ]}
90- data .append (row )
91-
92- if desc := f .get ("description" , "" ):
93- # MarkdownTable can't handle newlines, so replace with HTML equivalent
94- desc = desc .replace ("\n \n " , "<br /><br />" ).replace ("\n " , " " )
95- row = {"Field" : f"`{ f ['name' ]} `" , "Notes" : desc }
96- notes .append (row )
97-
98- data = [
99- {
81+ # MarkdownTable can't handle newlines, so replace with HTML equivalent
82+ desc = f .get ("description" , "" )
83+ desc = desc .replace ("\n \n " , "<br /><br />" ).replace ("\n " , " " )
84+ row = {
10085 "Field" : f"`{ f ['name' ]} `" ,
10186 "Description" : f ["title" ],
87+ "Notes" : desc ,
10288 }
103- for f in fields
104- ]
105-
89+ data .append (row )
10690 table = str (MarkdownTable .from_dicts (data ))
107- notes_table = str (MarkdownTable .from_dicts (notes )) if notes else None
108- return table , notes_table
91+ return table
10992
11093
11194if __name__ == "__main__" :
0 commit comments