Skip to content

Commit 473ed23

Browse files
pablukalecthomas
authored andcommitted
Update table.py to write changes on README.md
Write the up-to-date list of the supported languages directly on the README.md file in order to avoid manual copy/paste actions.
1 parent c788380 commit 473ed23

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

Diff for: table.py

+18-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
#!/usr/bin/env python3
2+
import re
23
from collections import defaultdict
34
from subprocess import check_output
45

6+
README_FILE = "README.md"
7+
8+
59
lines = check_output(["go", "run", "./cmd/chroma/main.go", "--list"]).decode("utf-8").splitlines()
610
lines = [line.strip() for line in lines if line.startswith(" ") and not line.startswith(" ")]
711
lines = sorted(lines, key=lambda l: l.lower())
@@ -11,5 +15,18 @@
1115
for line in lines:
1216
table[line[0].upper()].append(line)
1317

18+
rows = []
1419
for key, value in table.items():
15-
print("{} | {}".format(key, ", ".join(value)))
20+
rows.append("{} | {}".format(key, ", ".join(value)))
21+
tbody = "\n".join(rows)
22+
23+
with open(README_FILE, "r") as f:
24+
content = f.read()
25+
26+
with open(README_FILE, "w") as f:
27+
marker = re.compile(r"(?P<start>:----: \\| --------\n).*?(?P<end>\n\n)", re.DOTALL)
28+
replacement = r"\g<start>%s\g<end>" % tbody
29+
updated_content = marker.sub(replacement, content)
30+
f.write(updated_content)
31+
32+
print(tbody)

0 commit comments

Comments
 (0)