2424_SWAGGER_URL_PREFIX : Final [str ] = f"https://petstore.swagger.io/?url={ _URL_PREFIX } "
2525
2626
27- def _to_row (values : Iterable ):
28- return f"| { '|' .join (map (str , values ))} |\n "
29-
30-
3127class CaptureTuple (NamedTuple ):
3228 service_name : str
3329 file_path : Path
3430
3531
36- service_names_aliases : dict [str , str ] = {"web" : "webserver" }
32+ _service_names_aliases : dict [str , str ] = {
33+ "web" : "webserver" ,
34+ }
3735
3836
3937def generate_markdown_table (
4038 * captured_files : Iterable [CaptureTuple ],
4139) -> str :
4240 title = ("Name" , "Files" , " " )
41+ num_cols = len (title )
4342 lines = ["-" * 10 ] * len (title )
4443
45- table = _to_row (title )
46- table += _to_row (lines )
44+ def _to_row_data (values : Iterable ) -> list [str ]:
45+ row = list (map (str , values ))
46+ assert len (row ) == num_cols , f"len({ row = } ) != { num_cols = } "
47+ return row
48+
49+ rows = [
50+ _to_row_data (title ),
51+ _to_row_data (lines ),
52+ ]
4753
4854 found = itertools .groupby (
4955 sorted (itertools .chain (* captured_files ), key = attrgetter ("service_name" )),
5056 key = attrgetter ("service_name" ),
5157 )
5258
5359 for name , service_files in found :
54- table += _to_row (
55- (
56- f"**{ name .upper ()} **" ,
57- "" ,
58- "" ,
60+ rows .append (
61+ _to_row_data (
62+ (
63+ f"**{ name .upper ()} **" ,
64+ "" ,
65+ "" ,
66+ )
5967 )
6068 )
6169 for _ , file_path in service_files :
@@ -65,7 +73,7 @@ def generate_markdown_table(
6573 badges = []
6674
6775 if file_path .stem .lower () == "dockerfile" :
68- repo = service_names_aliases .get (f"{ name } " ) or name
76+ repo = _service_names_aliases .get (f"{ name } " ) or name
6977 badges = [
7078 f"[](https://hub.docker.com/r/itisfoundation/{ repo } /tags)"
7179 ]
@@ -76,16 +84,19 @@ def generate_markdown_table(
7684 f"[]({ _SWAGGER_URL_PREFIX } /{ file_path } )" ,
7785 ]
7886
79- table += _to_row (
80- (
81- "" ,
82- linked_path ,
83- " " .join (badges ),
87+ rows .append (
88+ _to_row_data (
89+ (
90+ "" ,
91+ linked_path ,
92+ " " .join (badges ),
93+ )
8494 )
8595 )
96+ rows .append (_to_row_data (["" * 10 ] * len (title )))
8697
87- table += _to_row ([ "" * 10 ] * len ( title ))
88- return table
98+ # converts to markdown table
99+ return " \n " . join ( f"| { '|' . join ( r ) } |" for r in rows )
89100
90101
91102if __name__ == "__main__" :
@@ -115,7 +126,7 @@ def _to_tuple(file: Path):
115126
116127 print ("# services" )
117128 print (">" )
118- print (f"> Auto generated on { now } by " )
129+ print (f"> Auto generated on ` { now } ` using " )
119130 print ("```cmd" )
120131 print ("cd osparc-simcore" )
121132 print (f"python ./{ CURRENT_FILE .relative_to (repo_base_path )} " )
0 commit comments