99import pandas as pd
1010import petab
1111
12- from _helpers import petab_yamls
12+ from _helpers import petab_yamls , readme_md
1313
1414
1515markdown_columns = {
@@ -145,8 +145,12 @@ def get_overview_table() -> pd.DataFrame:
145145 return df
146146
147147
148+ start_overview_table = '\n <!-- START OVERVIEW TABLE -->\n '
149+ end_overview_table = '\n <!-- END OVERVIEW TABLE -->\n '
150+
148151def main (
149- markdown : bool = False ,
152+ markdown : bool = False ,
153+ update_readme : bool = False ,
150154):
151155 df = get_overview_table ()
152156 pd .options .display .width = 0
@@ -163,7 +167,23 @@ def main(
163167 )
164168 df .index .rename (markdown_columns [index_column ], inplace = True )
165169 df .rename (columns = markdown_columns , inplace = True )
166- print (df .to_markdown ())
170+ markdown_overview = df .to_markdown ()
171+ if update_readme :
172+ with open (readme_md , "r" ) as f :
173+ readme_content = f .read ()
174+ before_table = readme_content .split (start_overview_table )[0 ]
175+ after_table = readme_content .split (end_overview_table )[1 ]
176+ new_readme_content = (
177+ before_table
178+ + start_overview_table
179+ + markdown_overview
180+ + end_overview_table
181+ + after_table
182+ )
183+ with open (readme_md , "w" ) as f :
184+ f .write (new_readme_content )
185+ else :
186+ print (markdown_overview )
167187 else :
168188 print (df )
169189
@@ -172,6 +192,10 @@ def main(
172192 import sys
173193
174194 markdown = False
195+ update_readme = False
175196 if '--markdown' in sys .argv :
176197 markdown = True
177- main (markdown )
198+ if '--update' in sys .argv :
199+ markdown = True
200+ update_readme = True
201+ main (markdown = markdown , update_readme = update_readme )
0 commit comments