Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions pytype_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,11 @@ def to_markdown(me, fp, returncode, results, branch_url):
mylink = 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(pd.DataFrame(results).to_markdown())
fp.write(f"\n#### {mylink} reports these error messages:\n")
if len(results):
fp.write(pd.DataFrame(results).to_markdown())
else:
fp.write(f"\n*pytype exited with error {returncode}, please check the CI logs*\n")
else:
fp.write(f"\n#### Congratulations, {mylink} reports no {pytype_link} errors.\n")
fp.write("\n")
Expand All @@ -152,6 +155,12 @@ def to_markdown(me, fp, returncode, results, branch_url):
def setup_and_run_pytype_action(scriptname: str):
config = load("pyproject.toml")
pytype = config["tool"].get("pytype")
if required := pytype.get("python_version", None):
if f"{sys.version_info[0]}.{sys.version_info[1]}" != required:
print(f"`pyproject.toml->tool.pytype->python_version` requires {required}!")
print("(It does not support 3.12: Fails to importing several pytest plugins.)")
raise RuntimeError(f"Python version {sys.version} does not match {required})")

xfail_files = pytype.get("xfail", []) if pytype else []
repository_url = config["project"]["urls"]["repository"].strip(" /")
filelink_baseurl = repository_url + "/blob/master"
Expand All @@ -163,13 +172,17 @@ def setup_and_run_pytype_action(scriptname: str):
branch = os.environ.get("GITHUB_HEAD_REF", None) or os.environ.get("GITHUB_REF_NAME", None)
filelink_baseurl = f"{server_url}/{repository}/blob/{branch}"
retcode, results = run_pytype_and_parse_annotations(xfail_files, filelink_baseurl)
# Write the panda dable to a markdown output file:
# Write the pandas table to a markdown output file:
summary_file = os.environ.get("GITHUB_STEP_SUMMARY", None)
if summary_file:
dirname = os.path.dirname(summary_file)
if dirname:
os.makedirs(dirname, exist_ok=True)
with open(summary_file, "w", encoding="utf-8") as fp:
to_markdown(scriptname, fp, retcode, results, filelink_baseurl)
else:
to_markdown(scriptname, sys.stdout, retcode, results, filelink_baseurl)
return retcode


if __name__ == "__main__":
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# .github/workflows/main.yml is set up to test with 3.11, 3.12 and 3.13 in parallel.
# Therefore, use three environments: One with 3.11, one with 3.12 and one with 3.13:
#
envlist = py311-covcp-check-mdreport, py312-cov-pytype, py313-cov-lint-pyright
envlist = py311-covcp-check-pytype-mdreport, py312-cov, py313-cov-lint-pyright
isolated_build = true
skip_missing_interpreters = true
requires =
Expand Down