forked from acts-project/acts
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add ability to mask FPEs from code comment (acts-project#2277)
Syntax is ```cpp float v = 1.0 / 0.0; // MARK: fpeMask(FLTDIV, 1) ``` where you can specify the FPE type, and the maximum number per event that is tolerated. You can add multiple `fpeMask()` expressions per line. NOTE: This will likely only work in case of running from the build directory, not from an installed one.
- Loading branch information
1 parent
71cec00
commit 4798aec
Showing
7 changed files
with
231 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
#!/usr/bin/env python3 | ||
from pathlib import Path | ||
import os | ||
import re | ||
import sys | ||
|
||
import asyncio | ||
import aiohttp | ||
import gidgethub | ||
from gidgethub.aiohttp import GitHubAPI | ||
import typer | ||
from rich import print | ||
from rich.rule import Rule | ||
|
||
|
||
def main( | ||
token: str = typer.Option(..., envvar="GITHUB_TOKEN"), | ||
repo: str = typer.Option(..., envvar="GITHUB_REPOSITORY"), | ||
): | ||
asyncio.run(check(token, repo)) | ||
|
||
|
||
async def check(token: str, repo: str): | ||
ok = True | ||
|
||
async with aiohttp.ClientSession() as session: | ||
gh = GitHubAPI(session=session, requester="acts-project", oauth_token=token) | ||
srcdir = Path(__file__).parent.parent | ||
for root, _, files in os.walk(srcdir): | ||
root = Path(root) | ||
for f in files: | ||
if ( | ||
not f.endswith(".hpp") | ||
and not f.endswith(".cpp") | ||
and not f.endswith(".ipp") | ||
): | ||
continue | ||
f = root / f | ||
rel = f.relative_to(srcdir) | ||
first = True | ||
with f.open("r") as fh: | ||
for i, line in enumerate(fh, start=1): | ||
if m := re.match(r".*\/\/ ?MARK: ?(fpeMask.*)$", line): | ||
if first: | ||
print(Rule(str(rel))) | ||
first = False | ||
exp = m.group(1) | ||
for m in re.findall( | ||
r"fpeMask\((\w+), ?(\d+) ?, ?issue: ?(\d+)\)", exp | ||
): | ||
fpeType, count, number = m | ||
|
||
loc = f"{rel}:{i}" | ||
this_ok = True | ||
issue_info = number | ||
try: | ||
issue = await gh.getitem( | ||
f"repos/{repo}/issues/{number}" | ||
) | ||
issue_info = issue["html_url"] | ||
except gidgethub.BadRequest as e: | ||
print( | ||
f":red_circle: [bold]FPE mask at {loc} has invalid issue number {number}[/bold]" | ||
) | ||
this_ok = False | ||
continue | ||
|
||
if issue["state"] != "open": | ||
print( | ||
f":red_circle: [bold]FPE mask at {loc} has issue {number} but is not open[/bold]" | ||
) | ||
this_ok = False | ||
if not "fpe" in issue["title"].lower(): | ||
print( | ||
f":red_circle: [bold]FPE mask at {loc} has issue {number} but does not contain 'FPE' / 'fpe' in the title[/bold]" | ||
) | ||
this_ok = False | ||
if not "fpe" in [l["name"] for l in issue["labels"]]: | ||
print( | ||
f":red_circle: [bold]FPE mask at {loc} has issue {number} but does not have the 'fpe' label[/bold]" | ||
) | ||
this_ok = False | ||
|
||
if this_ok: | ||
print( | ||
f":green_circle: [bold]FPE mask at {loc}: {fpeType} <= {count}[/bold]" | ||
) | ||
|
||
ok = ok and this_ok | ||
|
||
raise typer.Exit(code=0 if ok else 1) | ||
|
||
|
||
typer.run(main) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
gidgethub | ||
typer | ||
rich | ||
aiohttp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# | ||
# This file is autogenerated by pip-compile with Python 3.10 | ||
# by the following command: | ||
# | ||
# pip-compile CI/requirements_fpe_masks.in | ||
# | ||
aiohttp==3.8.4 | ||
# via -r CI/requirements_fpe_masks.in | ||
aiosignal==1.3.1 | ||
# via aiohttp | ||
async-timeout==4.0.2 | ||
# via aiohttp | ||
attrs==23.1.0 | ||
# via aiohttp | ||
cffi==1.15.1 | ||
# via cryptography | ||
charset-normalizer==3.1.0 | ||
# via aiohttp | ||
click==8.1.4 | ||
# via typer | ||
cryptography==41.0.1 | ||
# via pyjwt | ||
frozenlist==1.3.3 | ||
# via | ||
# aiohttp | ||
# aiosignal | ||
gidgethub==5.3.0 | ||
# via -r CI/requirements_fpe_masks.in | ||
idna==3.4 | ||
# via yarl | ||
markdown-it-py==3.0.0 | ||
# via rich | ||
mdurl==0.1.2 | ||
# via markdown-it-py | ||
multidict==6.0.4 | ||
# via | ||
# aiohttp | ||
# yarl | ||
pycparser==2.21 | ||
# via cffi | ||
pygments==2.15.1 | ||
# via rich | ||
pyjwt[crypto]==2.7.0 | ||
# via gidgethub | ||
rich==13.4.2 | ||
# via -r CI/requirements_fpe_masks.in | ||
typer==0.9.0 | ||
# via -r CI/requirements_fpe_masks.in | ||
typing-extensions==4.7.1 | ||
# via typer | ||
uritemplate==4.1.1 | ||
# via gidgethub | ||
yarl==1.9.2 | ||
# via aiohttp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters