Skip to content

Commit c839d59

Browse files
authored
Update check_all_schemas.py
1 parent a3230bf commit c839d59

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

scripts/check_all_schemas.py

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import subprocess
22
import os
33
import argparse
4+
import concurrent.futures
45

56
def run_schema_checker(script_name):
67
"""
@@ -10,7 +11,7 @@ def run_schema_checker(script_name):
1011
script_name (str): The filename of the shell script to run.
1112
1213
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.
1415
"""
1516
try:
1617
# Build the full path to the script
@@ -20,12 +21,12 @@ def run_schema_checker(script_name):
2021
# Print output and error from shell script
2122
print(result.stdout)
2223
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)
2627
except Exception as e:
2728
print(f"An error occurred while running {script_name}: {e}")
28-
return False
29+
return (script_name, False)
2930

3031
def main():
3132
parser = argparse.ArgumentParser(description="Run schema validations for specified datasets.")
@@ -41,15 +42,17 @@ def main():
4142
'mpnst': 'check_mpnst_linkml.sh'
4243
}
4344

44-
all_passed = True
4545
scripts_to_run = schema_mapping.values() if not args.datasets else [schema_mapping[dataset] for dataset in args.datasets if dataset in schema_mapping]
4646

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}")
5356

5457
if all_passed:
5558
print("All schema validations passed successfully.")

0 commit comments

Comments
 (0)