Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
check_fpe_masks.py
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file check_fpe_masks.py
1 #!/usr/bin/env python3
2 from pathlib import Path
3 import os
4 import re
5 import sys
6 
7 import asyncio
8 import aiohttp
9 import gidgethub
10 from gidgethub.aiohttp import GitHubAPI
11 import typer
12 from rich import print
13 from rich.rule import Rule
14 
15 
16 def main(
17  token: str = typer.Option(..., envvar="GITHUB_TOKEN"),
18  repo: str = typer.Option(..., envvar="GITHUB_REPOSITORY"),
19 ):
20  asyncio.run(check(token, repo))
21 
22 
23 async def check(token: str, repo: str):
24  ok = True
25 
26  async with aiohttp.ClientSession() as session:
27  gh = GitHubAPI(session=session, requester="acts-project", oauth_token=token)
28  srcdir = Path(__file__).parent.parent
29  for root, _, files in os.walk(srcdir):
30  root = Path(root)
31  for f in files:
32  if (
33  not f.endswith(".hpp")
34  and not f.endswith(".cpp")
35  and not f.endswith(".ipp")
36  ):
37  continue
38  f = root / f
39  rel = f.relative_to(srcdir)
40  first = True
41  with f.open("r") as fh:
42  for i, line in enumerate(fh, start=1):
43  if m := re.match(r".*\/\/ ?MARK: ?(fpeMask.*)$", line):
44  if first:
45  print(Rule(str(rel)))
46  first = False
47  exp = m.group(1)
48  for m in re.findall(
49  r"fpeMask(?:Begin)?\( ?(\w+), ?(\d+) ?, ?#(\d+) ?\)",
50  exp,
51  ):
52  fpeType, count, number = m
53 
54  loc = f"{rel}:{i}"
55  this_ok = True
56  issue_info = number
57  try:
58  issue = await gh.getitem(
59  f"repos/{repo}/issues/{number}"
60  )
61  issue_info = issue["html_url"]
62  except gidgethub.BadRequest as e:
63  print(
64  f":red_circle: [bold]FPE mask at {loc} has invalid issue number {number}[/bold]"
65  )
66  this_ok = False
67  continue
68 
69  if issue["state"] != "open":
70  print(
71  f":red_circle: [bold]FPE mask at {loc} has issue {number} but is not open[/bold]"
72  )
73  this_ok = False
74  if not "fpe" in issue["title"].lower():
75  print(
76  f":red_circle: [bold]FPE mask at {loc} has issue {number} but does not contain 'FPE' / 'fpe' in the title[/bold]"
77  )
78  this_ok = False
79  if not "fpe" in [l["name"] for l in issue["labels"]]:
80  print(
81  f":red_circle: [bold]FPE mask at {loc} has issue {number} but does not have the 'fpe' label[/bold]"
82  )
83  this_ok = False
84 
85  if this_ok:
86  print(
87  f":green_circle: [bold]FPE mask at {loc}: {fpeType} <= {count}[/bold]"
88  )
89 
90  ok = ok and this_ok
91 
92  raise typer.Exit(code=0 if ok else 1)
93 
94 
95 typer.run(main)