55import dataclasses
66import glob
77import io
8+ import itertools
89import json
910import pathlib
1011import typing
@@ -76,7 +77,7 @@ def main():
7677 pathname = "manifests/base/*.yaml"
7778 # pathname = 'manifests/overlays/additional/*.yaml'
7879 imagestreams : list [Manifest ] = []
79- for fn in glob .glob (pathname , root_dir = ROOT_DIR ):
80+ for fn in itertools . chain ( glob .glob (pathname , root_dir = ROOT_DIR ), glob . glob ( "manifests/overlays/additional/*.yaml" , root_dir = ROOT_DIR ) ):
8081 # there may be more than one yaml document in a file (e.g. rstudio buildconfigs)
8182 with open (ROOT_DIR / fn , "rt" ) as fp :
8283 for data in yaml .safe_load_all (fp ):
@@ -145,7 +146,7 @@ def main():
145146 print ("| Image name | Image version | Preinstalled packages |" )
146147 print ("|------------|---------------|-----------------------|" )
147148 for row in tabular_data :
148- print (f"| { row [ 0 ] } | { row [ 1 ] } | { row [ 2 ] } |" )
149+ print (f"| { ' | ' . join ( escape ( r ) for r in row ) } |" )
149150
150151 print ()
151152
@@ -157,10 +158,16 @@ def main():
157158 print ("Image name | Image version | Preinstalled packages" )
158159 print ("--------- | ---------" )
159160 for row in tabular_data :
160- print (f"{ row [ 0 ] } | { row [ 1 ] } | { row [ 2 ] } " )
161+ print (f"{ ' | ' . join ( escape ( r ) for r in row ) } " )
161162 print ("```" )
162163
163164
165+ def escape (s : str ) -> str :
166+ r"""> NOTE: To escape a character that would otherwise affect formatting (e.g. *, -, #, >, [, ], (, ), \, `)
167+ and render it literally, use a backslash (\) before the character."""
168+ return s .replace ("\\ " , "\\ \\ " ).replace ("|" , "\\ |" )
169+
170+
164171class TestManifest (unittest .TestCase ):
165172 _data = yaml .safe_load (io .StringIO (package_versions_selftestdata .imagestream ))
166173 manifest = Manifest (_data )
@@ -184,5 +191,11 @@ def test_tag_sw_python(self):
184191 assert self .manifest .tags [0 ].sw_python == [{"name" : "JupyterLab" , "version" : "4.2" }]
185192
186193
194+ class TestTabular (unittest .TestCase ):
195+ def test_escape (self ):
196+ assert escape ("|" ) == "\\ |"
197+ assert escape ("\\ " ) == "\\ \\ "
198+
199+
187200if __name__ == "__main__" :
188201 main ()
0 commit comments