44import os
55import pathlib
66import subprocess
7+ from argparse import Namespace
78from subprocess import CalledProcessError
9+ from typing import Optional
810
911
1012def resync_specs (directory : pathlib .Path , errored : dict [str , str ]) -> None :
1113 """Actually sync the specs"""
14+ print ("Beginning to sync specs" ) # noqa: T201
1215 for spec in os .scandir (directory ):
1316 if not spec .is_dir ():
1417 continue
@@ -24,11 +27,13 @@ def resync_specs(directory: pathlib.Path, errored: dict[str, str]) -> None:
2427 )
2528 except CalledProcessError as exc :
2629 errored [spec .name ] = exc .stderr
30+ print ("Done syncing specs" ) # noqa: T201
2731
2832
2933def apply_patches ():
34+ print ("Beginning to apply patches" ) # noqa: T201
3035 subprocess .run (["bash" , "./.evergreen/remove-unimplemented-tests.sh" ], check = True ) # noqa: S603, S607
31- subprocess .run (["git apply -R --allow-empty ./.evergreen/patch/*" ], shell = True , check = True ) # noqa: S602, S607
36+ subprocess .run (["git apply -R --allow-empty ./.evergreen/spec- patch/*" ], shell = True , check = True ) # noqa: S602, S607
3237
3338
3439def check_new_spec_directories (directory : pathlib .Path ) -> list [str ]:
@@ -61,7 +66,7 @@ def check_new_spec_directories(directory: pathlib.Path) -> list[str]:
6166 return list (spec_set - test_set )
6267
6368
64- def write_summary (errored : dict [str , str ], new : list [str ]) -> None :
69+ def write_summary (errored : dict [str , str ], new : list [str ], filename : Optional [ str ] ) -> None :
6570 """Generate the PR description"""
6671 pr_body = ""
6772 process = subprocess .run (
@@ -86,24 +91,29 @@ def write_summary(errored: dict[str, str], new: list[str]) -> None:
8691 pr_body += "\n -" .join (new )
8792 pr_body += "\n "
8893 if pr_body != "" :
89- with open ("spec_sync.txt" , "w" ) as f :
90- # replacements made for proper json
91- f .write (pr_body .replace ("\n " , "\\ n" ).replace ("\t " , "\\ t" ))
94+ if filename is None :
95+ print (f"\n { pr_body } " ) # noqa: T201
96+ else :
97+ with open (filename , "w" ) as f :
98+ # replacements made for proper json
99+ f .write (pr_body .replace ("\n " , "\\ n" ).replace ("\t " , "\\ t" ))
92100
93101
94- def main ():
102+ def main (args : Namespace ):
95103 directory = pathlib .Path ("./test" )
96104 errored : dict [str , str ] = {}
97105 resync_specs (directory , errored )
98106 apply_patches ()
99107 new = check_new_spec_directories (directory )
100- write_summary (errored , new )
108+ write_summary (errored , new , args . filename )
101109
102110
103111if __name__ == "__main__" :
104112 parser = argparse .ArgumentParser (
105113 description = "Python Script to resync all specs and generate summary for PR."
106114 )
107- parser .add_argument ("filename" , help = "Name of file for the summary to be written into." )
115+ parser .add_argument (
116+ "--filename" , help = "Name of file for the summary to be written into." , default = None
117+ )
108118 args = parser .parse_args ()
109- main ()
119+ main (args )
0 commit comments