4
4
import os
5
5
import pathlib
6
6
import subprocess
7
+ from argparse import Namespace
7
8
from subprocess import CalledProcessError
9
+ from typing import Optional
8
10
9
11
10
12
def resync_specs (directory : pathlib .Path , errored : dict [str , str ]) -> None :
11
13
"""Actually sync the specs"""
14
+ print ("Beginning to sync specs" ) # noqa: T201
12
15
for spec in os .scandir (directory ):
13
16
if not spec .is_dir ():
14
17
continue
@@ -24,11 +27,13 @@ def resync_specs(directory: pathlib.Path, errored: dict[str, str]) -> None:
24
27
)
25
28
except CalledProcessError as exc :
26
29
errored [spec .name ] = exc .stderr
30
+ print ("Done syncing specs" ) # noqa: T201
27
31
28
32
29
33
def apply_patches ():
34
+ print ("Beginning to apply patches" ) # noqa: T201
30
35
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
32
37
33
38
34
39
def check_new_spec_directories (directory : pathlib .Path ) -> list [str ]:
@@ -61,7 +66,7 @@ def check_new_spec_directories(directory: pathlib.Path) -> list[str]:
61
66
return list (spec_set - test_set )
62
67
63
68
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 :
65
70
"""Generate the PR description"""
66
71
pr_body = ""
67
72
process = subprocess .run (
@@ -86,24 +91,29 @@ def write_summary(errored: dict[str, str], new: list[str]) -> None:
86
91
pr_body += "\n -" .join (new )
87
92
pr_body += "\n "
88
93
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" ))
92
100
93
101
94
- def main ():
102
+ def main (args : Namespace ):
95
103
directory = pathlib .Path ("./test" )
96
104
errored : dict [str , str ] = {}
97
105
resync_specs (directory , errored )
98
106
apply_patches ()
99
107
new = check_new_spec_directories (directory )
100
- write_summary (errored , new )
108
+ write_summary (errored , new , args . filename )
101
109
102
110
103
111
if __name__ == "__main__" :
104
112
parser = argparse .ArgumentParser (
105
113
description = "Python Script to resync all specs and generate summary for PR."
106
114
)
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
+ )
108
118
args = parser .parse_args ()
109
- main ()
119
+ main (args )
0 commit comments