|
|
@@ -8,48 +8,33 @@ Exceptions. See /LICENSE for license information.
|
|
|
SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
|
"""
|
|
|
|
|
|
+import io
|
|
|
import os
|
|
|
import re
|
|
|
import sys
|
|
|
|
|
|
+# To support direct runs, ensure the pythonpath has the repo root.
|
|
|
+_PYTHONPATH = os.path.realpath(os.path.join(os.path.dirname(__file__), "../.."))
|
|
|
+if _PYTHONPATH not in sys.path:
|
|
|
+ sys.path.insert(0, _PYTHONPATH)
|
|
|
+
|
|
|
+from proposals.scripts import proposals
|
|
|
+
|
|
|
if __name__ == "__main__":
|
|
|
- # Read the proposal dir relative to this script.
|
|
|
- proposal_dir = os.path.realpath(
|
|
|
- os.path.join(os.path.dirname(sys.argv[0]), "../../proposals/")
|
|
|
- )
|
|
|
- print(proposal_dir)
|
|
|
+ proposals_path = proposals.get_path()
|
|
|
|
|
|
- # Identify proposal titles in the file list.
|
|
|
- proposals = [
|
|
|
- "<!-- This list is updated by src/scripts/update_proposal_list.py. "
|
|
|
- "-->",
|
|
|
- "",
|
|
|
- ]
|
|
|
- error = False
|
|
|
- for file in sorted(os.listdir(proposal_dir)):
|
|
|
- file_match = re.match(r"^p([0-9]{4})\.md$", file)
|
|
|
- if not file_match:
|
|
|
- continue
|
|
|
- with open(os.path.join(proposal_dir, file)) as f:
|
|
|
- content = f.read()
|
|
|
- title = content.split("\n")[0]
|
|
|
- title_match = re.match(r"^# (.*)$", title)
|
|
|
- if not title_match:
|
|
|
- print("ERROR: %s doesn't have a title on the first line." % file)
|
|
|
- error = True
|
|
|
- proposals.append(
|
|
|
- "- [%s - %s](%s)" % (file_match[1], title_match[1], file)
|
|
|
- )
|
|
|
- decision_file = "p%s_decision.md" % file_match[1]
|
|
|
- if os.path.exists(os.path.join(proposal_dir, decision_file)):
|
|
|
- proposals.append(" - [Decision](%s)" % decision_file)
|
|
|
- # We print batched errors for usability, but still need to exit with
|
|
|
- # failure.
|
|
|
- if error:
|
|
|
- sys.exit(1)
|
|
|
+ with io.StringIO() as out:
|
|
|
+ out.write("<!-- Generated by ./scripts/update_proposal_list.py -->\n\n")
|
|
|
+ results = out.getvalue()
|
|
|
+ for title, filename in proposals.get_list(proposals_path):
|
|
|
+ indent = ""
|
|
|
+ if filename.endswith("decision.md"):
|
|
|
+ indent = " "
|
|
|
+ out.write("%s- [%s](%s)\n" % (indent, title, filename))
|
|
|
+ toc = out.getvalue()
|
|
|
|
|
|
# Replace the README content if needed.
|
|
|
- readme_path = os.path.join(proposal_dir, "README.md")
|
|
|
+ readme_path = os.path.join(proposals_path, "README.md")
|
|
|
with open(readme_path) as f:
|
|
|
old_content = f.read()
|
|
|
proposals_re = re.compile(
|
|
|
@@ -62,9 +47,7 @@ if __name__ == "__main__":
|
|
|
"<!-- endproposals --> marker."
|
|
|
)
|
|
|
sys.exit(1)
|
|
|
- new_content = proposals_re.sub(
|
|
|
- r"\1\n%s\n\n\2" % "\n".join(proposals), old_content
|
|
|
- )
|
|
|
+ new_content = proposals_re.sub(r"\1\n%s\n\2" % toc, old_content)
|
|
|
if old_content != new_content:
|
|
|
print("Updating proposals/README.md")
|
|
|
with open(readme_path, "w") as f:
|