@@ -142,7 +142,9 @@ 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 " )
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 " )
146148 fp .write (pd .DataFrame (results ).to_markdown ())
147149 else :
148150 fp .write (f"\n #### Congratulations, { mylink } reports no { pytype_link } errors.\n " )
@@ -152,6 +154,13 @@ def to_markdown(me, fp, returncode, results, branch_url):
152154def setup_and_run_pytype_action (scriptname : str ):
153155 config = load ("pyproject.toml" )
154156 pytype = config ["tool" ].get ("pytype" )
157+ required_version = pytype .get ("python_version" )
158+ if required_version :
159+ if f"{ sys .version_info [0 ]} .{ sys .version_info [1 ]} " != required_version :
160+ print (f"pytype requires to run in exactly Python { required_version } !" )
161+ print ("It does not support 3.12: Fails to resolve importing several pytest plugins." )
162+ raise RuntimeError ("Not started with pyproject.toml->tool.pytype->python_version" )
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 panda 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 (os .path .dirname (summary_file ), 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
175188if __name__ == "__main__" :
0 commit comments