Skip to content

Commit d2a1e2e

Browse files
Fix running pytype analysis: Needs Python 3.11 (3.12 not supported yet)
Signed-off-by: Bernhard Kaindl <[email protected]>
1 parent e1ce4cc commit d2a1e2e

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

pytype_runner.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,11 @@ def to_markdown(me, fp, returncode, results, branch_url):
142142
mylink = f"[{me}]({branch_url}/{me}.py)"
143143
pytype_link = "[pytype](https://google.github.io/pytype)"
144144
if len(results) or returncode:
145-
fp.write(f"\n#### {mylink} reports these {pytype_link} error messages:\n")
146-
fp.write(pd.DataFrame(results).to_markdown())
145+
fp.write(f"\n#### {mylink} reports these error messages:\n")
146+
if len(results):
147+
fp.write(pd.DataFrame(results).to_markdown())
148+
else:
149+
fp.write(f"\n*pytype exited with error {returncode}, please check the CI logs*\n")
147150
else:
148151
fp.write(f"\n#### Congratulations, {mylink} reports no {pytype_link} errors.\n")
149152
fp.write("\n")
@@ -152,6 +155,12 @@ def to_markdown(me, fp, returncode, results, branch_url):
152155
def setup_and_run_pytype_action(scriptname: str):
153156
config = load("pyproject.toml")
154157
pytype = config["tool"].get("pytype")
158+
if required := pytype.get("python_version", None):
159+
if f"{sys.version_info[0]}.{sys.version_info[1]}" != required:
160+
print(f"`pyproject.toml->tool.pytype->python_version` requires {required}!")
161+
print("(It does not support 3.12: Fails to importing several pytest plugins.)")
162+
raise RuntimeError(f"Python version {sys.version} does not match {required})")
163+
155164
xfail_files = pytype.get("xfail", []) if pytype else []
156165
repository_url = config["project"]["urls"]["repository"].strip(" /")
157166
filelink_baseurl = repository_url + "/blob/master"
@@ -163,13 +172,17 @@ def setup_and_run_pytype_action(scriptname: str):
163172
branch = os.environ.get("GITHUB_HEAD_REF", None) or os.environ.get("GITHUB_REF_NAME", None)
164173
filelink_baseurl = f"{server_url}/{repository}/blob/{branch}"
165174
retcode, results = run_pytype_and_parse_annotations(xfail_files, filelink_baseurl)
166-
# Write the panda dable to a markdown output file:
175+
# Write the pandas table to a markdown output file:
167176
summary_file = os.environ.get("GITHUB_STEP_SUMMARY", None)
168177
if summary_file:
178+
dirname = os.path.dirname(summary_file)
179+
if dirname:
180+
os.makedirs(dirname, exist_ok=True)
169181
with open(summary_file, "w", encoding="utf-8") as fp:
170182
to_markdown(scriptname, fp, retcode, results, filelink_baseurl)
171183
else:
172184
to_markdown(scriptname, sys.stdout, retcode, results, filelink_baseurl)
185+
return retcode
173186

174187

175188
if __name__ == "__main__":

tox.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
# .github/workflows/main.yml is set up to test with 3.11, 3.12 and 3.13 in parallel.
1212
# Therefore, use three environments: One with 3.11, one with 3.12 and one with 3.13:
1313
#
14-
envlist = py311-covcp-check-mdreport, py312-cov-pytype, py313-cov-lint-pyright
14+
envlist = py311-covcp-check-pytype-mdreport, py312-cov, py313-cov-lint-pyright
1515
isolated_build = true
1616
skip_missing_interpreters = true
1717
requires =

0 commit comments

Comments
 (0)