@@ -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,13 @@ def to_markdown(me, fp, returncode, results, branch_url):
152155def 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 pandas 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
175189if __name__ == "__main__" :
0 commit comments