Skip to content

Commit a1d33fb

Browse files
authored
Merge pull request #1509 from jiridanek/ [rhoai-2.23] fix rendering of the supported configurations images table
2 parents ee729b0 + c6a0c5d commit a1d33fb

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

ci/package_versions.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import dataclasses
66
import glob
77
import io
8+
import itertools
89
import json
910
import pathlib
1011
import 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+
164171
class 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+
187200
if __name__ == "__main__":
188201
main()

0 commit comments

Comments
 (0)