From 7a1ed1b1a35de31cbd28ac276f3c01c7dc593f20 Mon Sep 17 00:00:00 2001 From: Bernhard Kaindl Date: Fri, 15 Nov 2024 12:00:00 +0100 Subject: [PATCH] pylint,pytype wrappers: Fix spell check on short variable names Signed-off-by: Bernhard Kaindl --- pylint_runner.py | 18 +++++++++--------- pytype_runner.py | 26 +++++++++++++------------- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/pylint_runner.py b/pylint_runner.py index ff935393..4f040256 100755 --- a/pylint_runner.py +++ b/pylint_runner.py @@ -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] @@ -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"] @@ -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) diff --git a/pytype_runner.py b/pytype_runner.py index 76ed0357..113971c1 100755 --- a/pytype_runner.py +++ b/pytype_runner.py @@ -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] + "
" + msg[msg_splitpos + 1 :], + "Error message": msg[:msg_split_pos] + "
" + msg[msg_split_pos + 1 :], "Error description": "", } # https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#setting-an-error-message @@ -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:] @@ -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 [] @@ -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))