Skip to content

Commit

Permalink
pylint,pytype wrappers: Fix spell check on short variable names
Browse files Browse the repository at this point in the history
Signed-off-by: Bernhard Kaindl <[email protected]>
  • Loading branch information
bernhardkaindl committed Nov 16, 2024
1 parent ed7bb9a commit 7a1ed1b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 22 deletions.
18 changes: 9 additions & 9 deletions pylint_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ def cleanup_results_dict(r, sym):
r["symbol"] = sym[:32]
r["message"] = r["message"][:96]
try:
dotpos = r["obj"].rindex(".") + 1
dot_pos = r["obj"].rindex(".") + 1
except ValueError:
dotpos = 0
r["obj"] = r["obj"][dotpos:].split("test_")[-1][:16]
dot_pos = 0
r["obj"] = r["obj"][dot_pos:].split("test_")[-1][:16]


suppress_msg = ["Unused variable 'e'"] # type: list[str]
Expand Down Expand Up @@ -218,22 +218,22 @@ def main(dirs: List[str], output_file: str, pylint_logfile: str, branch_url: str

def write_results_as_markdown_tables(branch_url, fp, panda_overview, panda_results):
me = os.path.basename(__file__)
mylink = f"[{me}]({branch_url}/{me})"
link = f"[{me}]({branch_url}/{me})"
# https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#multiline-markdown-content
fp.write(f"### PyLint breakdown from {mylink} on **xcp/\\*\\*/*.py**\n")
fp.write(f"### PyLint breakdown from {link} on **xcp/\\*\\*/*.py**\n")
fp.write(panda_overview.to_markdown())
fp.write(f"\n### PyLint results from {mylink} on **xcp/\\*\\*/*.py**\n")
fp.write(f"\n### PyLint results from {link} on **xcp/\\*\\*/*.py**\n")
fp.write(panda_results.to_markdown())


if __name__ == "__main__":
ghblob_url = "https://github.com/xenserver/python-libs/blob/master"
github_blob_url = "https://github.com/xenserver/python-libs/blob/master"
server_url = os.environ.get("GITHUB_SERVER_URL", None)
repository = os.environ.get("GITHUB_REPOSITORY", None)
if server_url and repository:
# https://github.com/orgs/community/discussions/5251 only set on Pull requests:
branch = os.environ.get("GITHUB_HEAD_REF", None) or os.environ.get("GITHUB_REF_NAME", None)
ghblob_url = f"{server_url}/{repository}/blob/{branch}"
github_blob_url = f"{server_url}/{repository}/blob/{branch}"

# Like the previous run-pylint.sh, check the xcp module by default:
dirs_to_check = sys.argv[1:] if len(sys.argv) > 1 else ["xcp", "tests"]
Expand All @@ -249,4 +249,4 @@ def write_results_as_markdown_tables(branch_url, fp, panda_overview, panda_resul
pylint_txt = os.environ.get("ENVLOGDIR", ".tox") + "/pylint.txt"

print("Checking:", str(dirs_to_check) + "; Writing report to:", step_summary)
main(dirs_to_check, step_summary, pylint_txt, ghblob_url)
main(dirs_to_check, step_summary, pylint_txt, github_blob_url)
26 changes: 13 additions & 13 deletions pytype_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ def generate_github_annotation(match: re.Match[str], branch_url: str) -> Tuple[s
func = match.group(3)
msg = match.group(4)
assert isinstance(msg, str)
msg_splitpos = msg.find(" ", 21)
msg_split_pos = msg.find(" ", 21)
file = match.group(1)
linktext = os.path.basename(file).split(".")[0]
source_link = f"[`{linktext}`]({branch_url}/{file}#L{lineno})"
link_text = os.path.basename(file).split(".")[0]
source_link = f"[`{link_text}`]({branch_url}/{file}#L{lineno})"
row = {
"Location": source_link,
"Function": f"`{func}`",
"Error code": code,
"Error message": msg[:msg_splitpos] + "<br>" + msg[msg_splitpos + 1 :],
"Error message": msg[:msg_split_pos] + "<br>" + msg[msg_split_pos + 1 :],
"Error description": "",
}
# https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#setting-an-error-message
Expand All @@ -49,8 +49,8 @@ def skip_uninteresting_lines(line: str) -> bool:
return True
if line[0] == "[":
pos = line.rfind(os.getcwd())
printfrom = pos + len(os.getcwd()) + 1 if pos > 0 else line.index("]") + 2
info("PROGRESS: " + line[1:].split("]")[0] + ": " + line[printfrom:])
print_from = pos + len(os.getcwd()) + 1 if pos > 0 else line.index("]") + 2
info("PROGRESS: " + line[1:].split("]")[0] + ": " + line[print_from:])
return True
if line.startswith("ninja: "):
line = line[7:]
Expand Down Expand Up @@ -139,17 +139,17 @@ def run_pytype_and_parse_annotations(xfail_files: List[str], branch_url: str):


def to_markdown(me, fp, returncode, results, branch_url):
mylink = f"[{me}]({branch_url}/{me}.py)"
my_link = f"[{me}]({branch_url}/{me}.py)"
pytype_link = "[pytype](https://google.github.io/pytype)"
if len(results) or returncode:
fp.write(f"\n#### {mylink} reports these {pytype_link} error messages:\n")
fp.write(f"\n#### {my_link} reports these {pytype_link} error messages:\n")
fp.write(pd.DataFrame(results).to_markdown())
else:
fp.write(f"\n#### Congratulations, {mylink} reports no {pytype_link} errors.\n")
fp.write(f"\n#### Congratulations, {my_link} reports no {pytype_link} errors.\n")
fp.write("\n")


def setup_and_run_pytype_action(scriptname: str):
def setup_and_run_pytype_action(script_name: str):
config = load("pyproject.toml")
pytype = config["tool"].get("pytype")
xfail_files = pytype.get("xfail", []) if pytype else []
Expand All @@ -167,12 +167,12 @@ def setup_and_run_pytype_action(scriptname: str):
summary_file = os.environ.get("GITHUB_STEP_SUMMARY", None)
if summary_file:
with open(summary_file, "w", encoding="utf-8") as fp:
to_markdown(scriptname, fp, retcode, results, filelink_baseurl)
to_markdown(script_name, fp, retcode, results, filelink_baseurl)
else:
to_markdown(scriptname, sys.stdout, retcode, results, filelink_baseurl)
to_markdown(script_name, sys.stdout, retcode, results, filelink_baseurl)


if __name__ == "__main__":
script_basename = os.path.basename(__file__).split(".")[0]
basicConfig(format=script_basename + ": %(message)s", level=INFO)
sys.exit(setup_and_run_pytype_action(scriptname=script_basename))
sys.exit(setup_and_run_pytype_action(script_name=script_basename))

0 comments on commit 7a1ed1b

Please sign in to comment.