You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

table.py 916B

1234567891011121314151617181920212223242526272829303132
  1. #!/usr/bin/env python3
  2. import re
  3. from collections import defaultdict
  4. from subprocess import check_output
  5. README_FILE = "README.md"
  6. lines = check_output(["go", "run", "./cmd/chroma/main.go", "--list"]).decode("utf-8").splitlines()
  7. lines = [line.strip() for line in lines if line.startswith(" ") and not line.startswith(" ")]
  8. lines = sorted(lines, key=lambda l: l.lower())
  9. table = defaultdict(list)
  10. for line in lines:
  11. table[line[0].upper()].append(line)
  12. rows = []
  13. for key, value in table.items():
  14. rows.append("{} | {}".format(key, ", ".join(value)))
  15. tbody = "\n".join(rows)
  16. with open(README_FILE, "r") as f:
  17. content = f.read()
  18. with open(README_FILE, "w") as f:
  19. marker = re.compile(r"(?P<start>:----: \\| --------\n).*?(?P<end>\n\n)", re.DOTALL)
  20. replacement = r"\g<start>%s\g<end>" % tbody
  21. updated_content = marker.sub(replacement, content)
  22. f.write(updated_content)
  23. print(tbody)