@@ -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):
152155def 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
175188if __name__ == "__main__" :
0 commit comments