From 473ed23c2abc83ad30098c0b17c89a1a21bfba17 Mon Sep 17 00:00:00 2001 From: Pablo SEMINARIO Date: Wed, 11 Nov 2020 15:25:43 +0100 Subject: [PATCH] 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. --- table.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/table.py b/table.py index 0b52b525f..779453982 100755 --- a/table.py +++ b/table.py @@ -1,7 +1,11 @@ #!/usr/bin/env python3 +import re from collections import defaultdict from subprocess import check_output +README_FILE = "README.md" + + lines = check_output(["go", "run", "./cmd/chroma/main.go", "--list"]).decode("utf-8").splitlines() lines = [line.strip() for line in lines if line.startswith(" ") and not line.startswith(" ")] lines = sorted(lines, key=lambda l: l.lower()) @@ -11,5 +15,18 @@ for line in lines: table[line[0].upper()].append(line) +rows = [] for key, value in table.items(): - print("{} | {}".format(key, ", ".join(value))) + rows.append("{} | {}".format(key, ", ".join(value))) +tbody = "\n".join(rows) + +with open(README_FILE, "r") as f: + content = f.read() + +with open(README_FILE, "w") as f: + marker = re.compile(r"(?P:----: \\| --------\n).*?(?P\n\n)", re.DOTALL) + replacement = r"\g%s\g" % tbody + updated_content = marker.sub(replacement, content) + f.write(updated_content) + +print(tbody)