[libcxx-commits] [libcxx] [libc++] Add script to create new Github issues for tracking conformance (PR #118139)
via libcxx-commits
libcxx-commits at lists.llvm.org
Fri Nov 29 13:47:46 PST 2024
github-actions[bot] wrote:
<!--LLVM CODE FORMAT COMMENT: {darker}-->
:warning: Python code formatter, darker found issues in your code. :warning:
<details>
<summary>
You can test this locally with the following command:
</summary>
``````````bash
darker --check --diff -r ae9b91acc76e03a3c38e2f92b59308c508901817...921ae2bc5d52e4c37fb569462bc9b9e3c86b0759 libcxx/utils/status-files.py
``````````
</details>
<details>
<summary>
View the diff from darker here.
</summary>
``````````diff
--- status-files.py 2024-11-29 21:43:25.000000 +0000
+++ status-files.py 2024-11-29 21:47:23.095788 +0000
@@ -16,13 +16,16 @@
import pathlib
import re
import subprocess
# Number of the 'Libc++ Standards Conformance' project on Github
-LIBCXX_CONFORMANCE_PROJECT = '31'
-
-def extract_between_markers(text: str, begin_marker: str, end_marker: str) -> Optional[str]:
+LIBCXX_CONFORMANCE_PROJECT = "31"
+
+
+def extract_between_markers(
+ text: str, begin_marker: str, end_marker: str
+) -> Optional[str]:
"""
Given a string containing special markers, extract everything located beetwen these markers.
If the beginning marker is not found, None is returned. If the beginning marker is found but
there is no end marker, it is an error (this is done to avoid silently accepting inputs that
@@ -30,16 +33,19 @@
"""
start = text.find(begin_marker)
if start == -1:
return None
- start += len(begin_marker) # skip the marker itself
+ start += len(begin_marker) # skip the marker itself
end = text.find(end_marker, start)
if end == -1:
- raise ArgumentError(f"Could not find end marker {end_marker} in: {text[start:]}")
+ raise ArgumentError(
+ f"Could not find end marker {end_marker} in: {text[start:]}"
+ )
return text[start:end]
+
class PaperStatus:
TODO = 1
IN_PROGRESS = 2
PARTIAL = 3
@@ -79,57 +85,60 @@
- '|In Progress|'
- '|Partial|'
- '|Complete|'
- '|Nothing To Do|'
"""
- if entry == '':
+ if entry == "":
return PaperStatus(PaperStatus.TODO, entry)
- elif entry == '|In Progress|':
+ elif entry == "|In Progress|":
return PaperStatus(PaperStatus.IN_PROGRESS, entry)
- elif entry == '|Partial|':
+ elif entry == "|Partial|":
return PaperStatus(PaperStatus.PARTIAL, entry)
- elif entry == '|Complete|':
+ elif entry == "|Complete|":
return PaperStatus(PaperStatus.DONE, entry)
- elif entry == '|Nothing To Do|':
+ elif entry == "|Nothing To Do|":
return PaperStatus(PaperStatus.NOTHING_TO_DO, entry)
else:
- raise RuntimeError(f'Unexpected CSV entry for status: {entry}')
+ raise RuntimeError(f"Unexpected CSV entry for status: {entry}")
@staticmethod
def from_github_issue(issue: Dict):
"""
Parse a paper status out of a Github issue obtained from querying a Github project.
"""
- if 'status' not in issue:
+ if "status" not in issue:
return PaperStatus(PaperStatus.TODO)
- elif issue['status'] == 'Todo':
+ elif issue["status"] == "Todo":
return PaperStatus(PaperStatus.TODO)
- elif issue['status'] == 'In Progress':
+ elif issue["status"] == "In Progress":
return PaperStatus(PaperStatus.IN_PROGRESS)
- elif issue['status'] == 'Partial':
+ elif issue["status"] == "Partial":
return PaperStatus(PaperStatus.PARTIAL)
- elif issue['status'] == 'Done':
+ elif issue["status"] == "Done":
return PaperStatus(PaperStatus.DONE)
- elif issue['status'] == 'Nothing To Do':
+ elif issue["status"] == "Nothing To Do":
return PaperStatus(PaperStatus.NOTHING_TO_DO)
else:
- raise RuntimeError(f"Received unrecognizable Github issue status: {issue['status']}")
+ raise RuntimeError(
+ f"Received unrecognizable Github issue status: {issue['status']}"
+ )
def to_csv_entry(self) -> str:
"""
Return the issue state formatted for a CSV entry. The status is formatted as '|Complete|',
'|In Progress|', etc.
"""
mapping = {
- PaperStatus.TODO: '',
- PaperStatus.IN_PROGRESS: '|In Progress|',
- PaperStatus.PARTIAL: '|Partial|',
- PaperStatus.DONE: '|Complete|',
- PaperStatus.NOTHING_TO_DO: '|Nothing To Do|',
+ PaperStatus.TODO: "",
+ PaperStatus.IN_PROGRESS: "|In Progress|",
+ PaperStatus.PARTIAL: "|Partial|",
+ PaperStatus.DONE: "|Complete|",
+ PaperStatus.NOTHING_TO_DO: "|Nothing To Do|",
}
return self._original if self._original is not None else mapping[self._status]
+
class PaperInfo:
paper_number: str
"""
Identifier for the paper or the LWG issue. This must be something like 'PnnnnRx', 'Nxxxxx' or 'LWGxxxxx'.
"""
@@ -164,39 +173,49 @@
"""
Object from which this PaperInfo originated. This is used to track the CSV row or Github issue that
was used to generate this PaperInfo and is useful for error reporting purposes.
"""
- def __init__(self, paper_number: str, paper_name: str,
- status: PaperStatus,
- meeting: Optional[str] = None,
- first_released_version: Optional[str] = None,
- notes: Optional[str] = None,
- original: Optional[object] = None):
+ def __init__(
+ self,
+ paper_number: str,
+ paper_name: str,
+ status: PaperStatus,
+ meeting: Optional[str] = None,
+ first_released_version: Optional[str] = None,
+ notes: Optional[str] = None,
+ original: Optional[object] = None,
+ ):
self.paper_number = paper_number
self.paper_name = paper_name
self.status = status
self.meeting = meeting
self.first_released_version = first_released_version
self.notes = notes
self.original = original
def for_printing(self) -> Tuple[str, str, str, str, str, str]:
return (
- f'`{self.paper_number} <https://wg21.link/{self.paper_number}>`__',
+ f"`{self.paper_number} <https://wg21.link/{self.paper_number}>`__",
self.paper_name,
- self.meeting if self.meeting is not None else '',
+ self.meeting if self.meeting is not None else "",
self.status.to_csv_entry(),
- self.first_released_version if self.first_released_version is not None else '',
- self.notes if self.notes is not None else '',
+ self.first_released_version
+ if self.first_released_version is not None
+ else "",
+ self.notes if self.notes is not None else "",
)
def __repr__(self) -> str:
- return repr(self.original) if self.original is not None else repr(self.for_printing())
+ return (
+ repr(self.original)
+ if self.original is not None
+ else repr(self.for_printing())
+ )
@staticmethod
- def from_csv_row(row: Tuple[str, str, str, str, str, str]):# -> PaperInfo:
+ def from_csv_row(row: Tuple[str, str, str, str, str, str]): # -> PaperInfo:
"""
Given a row from one of our status-tracking CSV files, create a PaperInfo object representing that row.
"""
# Extract the paper number from the first column
match = re.search(r"((P[0-9R]+)|(LWG[0-9]+)|(N[0-9]+))\s+", row[0])
@@ -212,34 +231,39 @@
notes=row[5] or None,
original=row,
)
@staticmethod
- def from_github_issue(issue: Dict):# -> PaperInfo:
+ def from_github_issue(issue: Dict): # -> PaperInfo:
"""
Create a PaperInfo object from the Github issue information obtained from querying a Github Project.
"""
# Extract the paper number from the issue title
- match = re.search(r"((P[0-9R]+)|(LWG[0-9]+)|(N[0-9]+)):", issue['title'])
+ match = re.search(r"((P[0-9R]+)|(LWG[0-9]+)|(N[0-9]+)):", issue["title"])
if match is None:
- raise RuntimeError(f"Issue doesn't have a title that we know how to parse: {issue}")
+ raise RuntimeError(
+ f"Issue doesn't have a title that we know how to parse: {issue}"
+ )
paper = match.group(1)
# Extract any notes from the Github issue and populate the RST notes with them
- issue_description = issue['content']['body']
- notes = extract_between_markers(issue_description, 'BEGIN-RST-NOTES', 'END-RST-NOTES')
+ issue_description = issue["content"]["body"]
+ notes = extract_between_markers(
+ issue_description, "BEGIN-RST-NOTES", "END-RST-NOTES"
+ )
notes = notes.strip() if notes is not None else notes
return PaperInfo(
paper_number=paper,
- paper_name=issue['title'],
+ paper_name=issue["title"],
status=PaperStatus.from_github_issue(issue),
- meeting=issue.get('meeting Voted', None),
- first_released_version=None, # TODO
+ meeting=issue.get("meeting Voted", None),
+ first_released_version=None, # TODO
notes=notes,
original=issue,
)
+
def merge(paper: PaperInfo, gh: PaperInfo) -> PaperInfo:
"""
Merge a paper coming from a CSV row with a corresponding Github-tracked paper.
@@ -252,36 +276,43 @@
is not useful.
In case we don't update the CSV row's status, we still take any updated notes coming
from the Github issue.
"""
- if paper.status == PaperStatus(PaperStatus.TODO) and gh.status == PaperStatus(PaperStatus.IN_PROGRESS):
+ if paper.status == PaperStatus(PaperStatus.TODO) and gh.status == PaperStatus(
+ PaperStatus.IN_PROGRESS
+ ):
result = copy.deepcopy(paper)
result.notes = gh.notes
elif paper.status < gh.status:
result = copy.deepcopy(gh)
elif paper.status == gh.status:
result = copy.deepcopy(paper)
result.notes = gh.notes
else:
- print(f"We found a CSV row and a Github issue with different statuses:\nrow: {paper}\nGithub issue: {gh}")
+ print(
+ f"We found a CSV row and a Github issue with different statuses:\nrow: {paper}\nGithub issue: {gh}"
+ )
result = copy.deepcopy(paper)
return result
+
def load_csv(file: pathlib.Path) -> List[Tuple]:
rows = []
- with open(file, newline='') as f:
- reader = csv.reader(f, delimiter=',')
+ with open(file, newline="") as f:
+ reader = csv.reader(f, delimiter=",")
for row in reader:
rows.append(row)
return rows
+
def write_csv(output: pathlib.Path, rows: List[Tuple]):
- with open(output, 'w', newline='') as f:
- writer = csv.writer(f, quoting=csv.QUOTE_ALL, lineterminator='\n')
+ with open(output, "w", newline="") as f:
+ writer = csv.writer(f, quoting=csv.QUOTE_ALL, lineterminator="\n")
for row in rows:
writer.writerow(row)
+
def sync_csv(rows: List[Tuple], from_github: List[PaperInfo]) -> List[Tuple]:
"""
Given a list of CSV rows representing an existing status file and a list of PaperInfos representing
up-to-date (but potentially incomplete) tracking information from Github, this function returns the
@@ -289,12 +320,12 @@
Note that this only tracks changes from 'not implemented' issues to 'implemented'. If an up-to-date
PaperInfo reports that a paper is not implemented but the existing CSV rows report it as implemented,
it is an error (i.e. the result is not a CSV row where the paper is *not* implemented).
"""
- results = [rows[0]] # Start with the header
- for row in rows[1:]: # Skip the header
+ results = [rows[0]] # Start with the header
+ for row in rows[1:]: # Skip the header
# If the row contains empty entries, this is a "separator row" between meetings.
# Preserve it as-is.
if row[0] == "":
results.append(row)
continue
@@ -312,84 +343,128 @@
results.append(row)
continue
# If there's more than one tracking issue, something is weird too.
if len(tracking) > 1:
- print(f"Found a row with more than one tracking issue: {row}\ntracked by: {tracking}")
+ print(
+ f"Found a row with more than one tracking issue: {row}\ntracked by: {tracking}"
+ )
results.append(row)
continue
results.append(merge(paper, tracking[0]).for_printing())
return results
+
def create_github_issues(rows: List[Tuple], labels: List[str]) -> None:
"""
Given a list of CSV rows representing newly voted issues and papers, create the Github issues
representing those and add them to the conformance table.
"""
for row in rows:
paper = PaperInfo.from_csv_row(row)
- paper_name = paper.paper_name.replace('``', '`').replace('\\', '')
-
- create_cli = ['gh', 'issue', 'create', '--repo', 'llvm/llvm-project',
- '--title', f'{paper.paper_number}: {paper_name}',
- '--body', f'**Link:** https://wg21.link/{paper.paper_number}',
- '--project', 'libc++ Standards Conformance',
- '--label', 'libc++']
+ paper_name = paper.paper_name.replace("``", "`").replace("\\", "")
+
+ create_cli = [
+ "gh",
+ "issue",
+ "create",
+ "--repo",
+ "llvm/llvm-project",
+ "--title",
+ f"{paper.paper_number}: {paper_name}",
+ "--body",
+ f"**Link:** https://wg21.link/{paper.paper_number}",
+ "--project",
+ "libc++ Standards Conformance",
+ "--label",
+ "libc++",
+ ]
for label in labels:
- create_cli += ['--label', label]
+ create_cli += ["--label", label]
issue_link = subprocess.check_output(create_cli).decode().strip()
print(f"\nCreated tracking issue for {paper.paper_number}: {issue_link}")
# TODO: It would be possible to adjust the "Meeting voted" field automatically, but we need
# the ID of the just-created issue.
# adjust_meeting = ['gh', 'project', 'item-edit', '--project-id', 'PVT_kwDOAQWwKc4AlOgt',
# '--field-id', 'PVTF_lADOAQWwKc4AlOgtzgdUEXI',
# '--text', paper.meeting, '--id', tracking.original['id']]
+
CSV_FILES_TO_SYNC = [
- 'Cxx17Issues.csv',
- 'Cxx17Papers.csv',
- 'Cxx20Issues.csv',
- 'Cxx20Papers.csv',
- 'Cxx23Issues.csv',
- 'Cxx23Papers.csv',
- 'Cxx2cIssues.csv',
- 'Cxx2cPapers.csv',
+ "Cxx17Issues.csv",
+ "Cxx17Papers.csv",
+ "Cxx20Issues.csv",
+ "Cxx20Papers.csv",
+ "Cxx23Issues.csv",
+ "Cxx23Papers.csv",
+ "Cxx2cIssues.csv",
+ "Cxx2cPapers.csv",
]
+
def main(argv):
import argparse
- parser = argparse.ArgumentParser(prog='status-files',
- description='Manipulate the libc++ conformance status files and Github issues')
- parser.add_argument('--synchronize', action='store_true', help="Synchronize the CSV files with the online Github issues.")
- parser.add_argument('--create-new', help="Create new Github issues from the CSV rows located in the given file.")
- parser.add_argument('--labels', nargs='+', help="When creating new Github issues, this is a list of labels to use on the created issues (e.g. lwg-issue, wg21 paper, c++23).")
+
+ parser = argparse.ArgumentParser(
+ prog="status-files",
+ description="Manipulate the libc++ conformance status files and Github issues",
+ )
+ parser.add_argument(
+ "--synchronize",
+ action="store_true",
+ help="Synchronize the CSV files with the online Github issues.",
+ )
+ parser.add_argument(
+ "--create-new",
+ help="Create new Github issues from the CSV rows located in the given file.",
+ )
+ parser.add_argument(
+ "--labels",
+ nargs="+",
+ help="When creating new Github issues, this is a list of labels to use on the created issues (e.g. lwg-issue, wg21 paper, c++23).",
+ )
args = parser.parse_args(argv)
if args.synchronize:
- libcxx_root = pathlib.Path(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
+ libcxx_root = pathlib.Path(
+ os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
+ )
# Extract the list of PaperInfos from issues we're tracking on Github.
print("Loading all issues from Github")
- gh_command_line = ['gh', 'project', 'item-list', LIBCXX_CONFORMANCE_PROJECT, '--owner', 'llvm', '--format', 'json', '--limit', '9999999']
+ gh_command_line = [
+ "gh",
+ "project",
+ "item-list",
+ LIBCXX_CONFORMANCE_PROJECT,
+ "--owner",
+ "llvm",
+ "--format",
+ "json",
+ "--limit",
+ "9999999",
+ ]
project_info = json.loads(subprocess.check_output(gh_command_line))
- from_github = [PaperInfo.from_github_issue(i) for i in project_info['items']]
+ from_github = [PaperInfo.from_github_issue(i) for i in project_info["items"]]
for filename in CSV_FILES_TO_SYNC:
print(f"Synchronizing {filename} with Github issues")
- file = libcxx_root / 'docs' / 'Status' / filename
+ file = libcxx_root / "docs" / "Status" / filename
csv = load_csv(file)
synced = sync_csv(csv, from_github)
write_csv(file, synced)
elif args.create_new:
print(f"Creating new Github issues from {args.create_new}")
new = load_csv(args.create_new)
create_github_issues(new, args.labels)
-if __name__ == '__main__':
+
+if __name__ == "__main__":
import sys
+
main(sys.argv[1:])
``````````
</details>
https://github.com/llvm/llvm-project/pull/118139
More information about the libcxx-commits
mailing list