17
17
18
18
import os
19
19
import subprocess
20
+ import sys
20
21
from glob import glob
21
22
from pathlib import Path
22
23
@@ -34,10 +35,14 @@ def cleanup(source_dir: Path, output_dir: Path, patterns: list[str]):
34
35
def run (
35
36
rule : unasync .Rule ,
36
37
cleanup_patterns : list [str ] = [],
38
+ check : bool = False ,
37
39
):
38
40
root_dir = Path (__file__ ).absolute ().parent .parent
39
41
source_dir = root_dir / rule .fromdir .lstrip ("/" )
40
- output_dir = root_dir / rule .todir .lstrip ("/" )
42
+ output_dir = check_dir = root_dir / rule .todir .lstrip ("/" )
43
+ if check :
44
+ rule .todir += "_sync_check/"
45
+ output_dir = root_dir / rule .todir .lstrip ("/" )
41
46
42
47
filepaths = []
43
48
for root , _ , filenames in os .walk (source_dir ):
@@ -53,8 +58,23 @@ def run(
53
58
if cleanup_patterns :
54
59
cleanup (source_dir , output_dir , cleanup_patterns )
55
60
61
+ if check :
62
+ subprocess .check_call (["black" , output_dir ])
63
+ subprocess .check_call (["isort" , "--profile=black" , output_dir ])
56
64
57
- def main ():
65
+ # make sure there are no differences between _sync and _sync_check
66
+ for file in glob ("*.py" , root_dir = output_dir ):
67
+ subprocess .check_call (
68
+ [
69
+ "diff" ,
70
+ f"{ check_dir } /{ file } " ,
71
+ f"{ output_dir } /{ file } " ,
72
+ ]
73
+ )
74
+ subprocess .check_call (["rm" , "-rf" , output_dir ])
75
+
76
+
77
+ def main (check : bool = False ):
58
78
run (
59
79
rule = unasync .Rule (
60
80
fromdir = "/elasticsearch/_async/client/" ,
@@ -69,6 +89,7 @@ def main():
69
89
"_TYPE_ASYNC_SNIFF_CALLBACK" : "_TYPE_SYNC_SNIFF_CALLBACK" ,
70
90
},
71
91
),
92
+ check = check ,
72
93
)
73
94
74
95
run (
@@ -93,8 +114,9 @@ def main():
93
114
cleanup_patterns = [
94
115
"/^import asyncio$/d" ,
95
116
],
117
+ check = check ,
96
118
)
97
119
98
120
99
121
if __name__ == "__main__" :
100
- main ()
122
+ main (check = "--check" in sys . argv )
0 commit comments