Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:10:43

0001 #!/usr/bin/env python3
0002 from pathlib import Path
0003 import os
0004 import re
0005 
0006 import asyncio
0007 import aiohttp
0008 import gidgethub
0009 from gidgethub.aiohttp import GitHubAPI
0010 import typer
0011 from rich import print
0012 from rich.rule import Rule
0013 
0014 
0015 def main(
0016     token: str = typer.Option(..., envvar="GITHUB_TOKEN"),
0017     repo: str = typer.Option(..., envvar="GITHUB_REPOSITORY"),
0018 ):
0019     asyncio.run(check(token, repo))
0020 
0021 
0022 async def check(token: str, repo: str):
0023     ok = True
0024 
0025     async with aiohttp.ClientSession() as session:
0026         gh = GitHubAPI(session=session, requester="acts-project", oauth_token=token)
0027         srcdir = Path(__file__).parent.parent
0028         for root, _, files in os.walk(srcdir):
0029             root = Path(root)
0030             for f in files:
0031                 if (
0032                     not f.endswith(".hpp")
0033                     and not f.endswith(".cpp")
0034                     and not f.endswith(".ipp")
0035                 ):
0036                     continue
0037                 f = root / f
0038                 rel = f.relative_to(srcdir)
0039                 first = True
0040                 with f.open("r") as fh:
0041                     for i, line in enumerate(fh, start=1):
0042                         if m := re.match(r".*\/\/ ?MARK: ?(fpeMask.*)$", line):
0043                             if first:
0044                                 print(Rule(str(rel)))
0045                             first = False
0046                             exp = m.group(1)
0047                             for m in re.findall(
0048                                 r"fpeMask(?:Begin)?\( ?(\w+), ?(\d+) ?, ?#(\d+) ?\)",
0049                                 exp,
0050                             ):
0051                                 fpeType, count, number = m
0052 
0053                                 loc = f"{rel}:{i}"
0054                                 this_ok = True
0055                                 try:
0056                                     issue = await gh.getitem(
0057                                         f"repos/{repo}/issues/{number}"
0058                                     )
0059                                 except gidgethub.BadRequest as e:
0060                                     print(
0061                                         f":red_circle: [bold]FPE mask at {loc} has invalid issue number {number}[/bold]"
0062                                     )
0063                                     this_ok = False
0064                                     continue
0065 
0066                                 if issue["state"] != "open":
0067                                     print(
0068                                         f":red_circle: [bold]FPE mask at {loc} has issue {number} but is not open[/bold]"
0069                                     )
0070                                     this_ok = False
0071                                 if not "fpe" in issue["title"].lower():
0072                                     print(
0073                                         f":red_circle: [bold]FPE mask at {loc} has issue {number} but does not contain 'FPE' / 'fpe' in the title[/bold]"
0074                                     )
0075                                     this_ok = False
0076                                 if not "fpe" in [l["name"] for l in issue["labels"]]:
0077                                     print(
0078                                         f":red_circle: [bold]FPE mask at {loc} has issue {number} but does not have the 'fpe' label[/bold]"
0079                                     )
0080                                     this_ok = False
0081 
0082                                 if this_ok:
0083                                     print(
0084                                         f":green_circle: [bold]FPE mask at {loc}: {fpeType} <= {count}[/bold]"
0085                                     )
0086 
0087                                 ok = ok and this_ok
0088 
0089     raise typer.Exit(code=0 if ok else 1)
0090 
0091 
0092 typer.run(main)