Skip to content

Commit b46f865

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 b46f865

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

pytype_runner.py

Lines changed: 17 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 not len(results):
147+
fp.write(f"\n*pytype exited with error {returncode}, please check the CI logs*\n")
148+
elif len(results):
149+
fp.write(pd.DataFrame(results).to_markdown())
147150
else:
148151
fp.write(f"\n#### Congratulations, {mylink} reports no {pytype_link} errors.\n")
149152
fp.write("\n")
@@ -152,6 +155,13 @@ 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+
required_version = pytype.get("python_version")
159+
if required_version:
160+
if f"{sys.version_info[0]}.{sys.version_info[1]}" != required_version:
161+
print(f"pytype requires to run in exactly Python {required_version}!")
162+
print("It does not support 3.12: Fails to resolve importing several pytest plugins.")
163+
raise RuntimeError("Not started with pyproject.toml->tool.pytype->python_version")
164+
155165
xfail_files = pytype.get("xfail", []) if pytype else []
156166
repository_url = config["project"]["urls"]["repository"].strip(" /")
157167
filelink_baseurl = repository_url + "/blob/master"
@@ -163,13 +173,17 @@ def setup_and_run_pytype_action(scriptname: str):
163173
branch = os.environ.get("GITHUB_HEAD_REF", None) or os.environ.get("GITHUB_REF_NAME", None)
164174
filelink_baseurl = f"{server_url}/{repository}/blob/{branch}"
165175
retcode, results = run_pytype_and_parse_annotations(xfail_files, filelink_baseurl)
166-
# Write the panda dable to a markdown output file:
176+
# Write the panda table to a markdown output file:
167177
summary_file = os.environ.get("GITHUB_STEP_SUMMARY", None)
168178
if summary_file:
179+
dirname = os.path.dirname(summary_file)
180+
if dirname:
181+
os.makedirs(dirname, exist_ok=True)
169182
with open(summary_file, "w", encoding="utf-8") as fp:
170183
to_markdown(scriptname, fp, retcode, results, filelink_baseurl)
171184
else:
172185
to_markdown(scriptname, sys.stdout, retcode, results, filelink_baseurl)
186+
return retcode
173187

174188

175189
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)