11import argparse
22import re
3- import shlex
43import subprocess
54from dataclasses import dataclass
65from pathlib import Path
7- from typing import Dict , List
6+ from typing import Any , Dict , List
7+
8+ import yaml
89
910TEST_INFO_DIR : Dict [str , str ] = {
1011 "c" : "c" ,
1415 "swift" : "swift" ,
1516}
1617
17- BUILD_PATTERN = re .compile (r"""^\s+build:\s*['"]([^'"]+)""" , re .M )
1818SOURCE_NAME_PATTERN = re .compile (r"\{\{\s*source\.name\s*\}\}" )
1919SOURCE_EXTENSION_PATTERN = re .compile (r"\{\{\s*source\.extension\s*\}\}" )
2020
2323class TestInfoStruct :
2424 path : Path
2525 language : str
26- test_info_str : str
26+ build : str
2727
2828
2929def main ():
@@ -36,22 +36,21 @@ def main():
3636 path = Path (changed_file )
3737 print (f"Building { path } " )
3838 command = get_build_command (testinfo_struct , path )
39- subprocess .run (command , cwd = path .parent , check = True )
39+ subprocess .run (command , cwd = path .parent , check = True , shell = True )
4040
4141
4242def get_test_info_struct (language : str ) -> TestInfoStruct :
4343 path = Path ("archive" ) / language [0 ] / TEST_INFO_DIR [language ] / "testinfo.yml"
44- testinfo_str = path .read_text ( encoding = "utf-8" )
45- return TestInfoStruct ( path = path , language = language , test_info_str = testinfo_str )
44+ with path .open () as f :
45+ testinfo = yaml . safe_load ( f )
4646
47+ return TestInfoStruct (path = path , language = language , build = testinfo ["container" ]["build" ])
4748
48- def get_build_command (testinfo_struct : TestInfoStruct , path : Path ) -> List [str ]:
49- match_str = BUILD_PATTERN .search (testinfo_struct .test_info_str )
50- assert match_str
5149
52- build = SOURCE_NAME_PATTERN .sub (path .stem , match_str .group (1 ))
50+ def get_build_command (testinfo_struct : TestInfoStruct , path : Path ) -> str :
51+ build = SOURCE_NAME_PATTERN .sub (path .stem , testinfo_struct .build )
5352 build = SOURCE_EXTENSION_PATTERN .sub (path .suffix , build )
54- return shlex . split ( build )
53+ return build
5554
5655
5756if __name__ == "__main__" :
0 commit comments