1
1
import subprocess
2
2
import os
3
3
import argparse
4
+ import concurrent .futures
4
5
5
6
def run_schema_checker (script_name ):
6
7
"""
@@ -10,7 +11,7 @@ def run_schema_checker(script_name):
10
11
script_name (str): The filename of the shell script to run.
11
12
12
13
Returns:
13
- bool: True if the validation succeeded, False if it failed.
14
+ tuple: (script_name, bool) where bool is True if the validation succeeded, False if it failed.
14
15
"""
15
16
try :
16
17
# Build the full path to the script
@@ -20,12 +21,12 @@ def run_schema_checker(script_name):
20
21
# Print output and error from shell script
21
22
print (result .stdout )
22
23
if result .stderr :
23
- print ("Error:" , result .stderr )
24
- # Return True if the script executed successfully
25
- return result .returncode == 0
24
+ print (f "Error in { script_name } :" , result .stderr )
25
+ # Return the script name and True if the script executed successfully
26
+ return ( script_name , result .returncode == 0 )
26
27
except Exception as e :
27
28
print (f"An error occurred while running { script_name } : { e } " )
28
- return False
29
+ return ( script_name , False )
29
30
30
31
def main ():
31
32
parser = argparse .ArgumentParser (description = "Run schema validations for specified datasets." )
@@ -41,15 +42,17 @@ def main():
41
42
'mpnst' : 'check_mpnst_linkml.sh'
42
43
}
43
44
44
- all_passed = True
45
45
scripts_to_run = schema_mapping .values () if not args .datasets else [schema_mapping [dataset ] for dataset in args .datasets if dataset in schema_mapping ]
46
46
47
- # Iterate over each script and run it
48
- for script_name in scripts_to_run :
49
- print (f"Running { script_name } ..." )
50
- if not run_schema_checker (script_name ):
51
- all_passed = False
52
- print (f"Validation failed for { script_name } " )
47
+ all_passed = True
48
+ with concurrent .futures .ThreadPoolExecutor () as executor :
49
+ futures = {executor .submit (run_schema_checker , script ): script for script in scripts_to_run }
50
+
51
+ for future in concurrent .futures .as_completed (futures ):
52
+ script_name , result = future .result ()
53
+ if not result :
54
+ all_passed = False
55
+ print (f"Validation failed for { script_name } " )
53
56
54
57
if all_passed :
55
58
print ("All schema validations passed successfully." )
0 commit comments