|
| 1 | +import os |
| 2 | +import re |
| 3 | +import subprocess |
| 4 | +from concurrent.futures import ThreadPoolExecutor |
| 5 | + |
| 6 | +exclude_file = '.ci/.exclude_files' |
| 7 | +root_dir = os.path.curdir |
| 8 | + |
| 9 | +with open(exclude_file, 'r') as f: |
| 10 | + exclude_patterns = [re.compile(line.strip()) for line in f.readlines()] |
| 11 | + |
| 12 | +def find_py_files(root_dir, exclude_patterns): |
| 13 | + py_files = [] |
| 14 | + for root, dirs, files in os.walk(root_dir): |
| 15 | + for file in files: |
| 16 | + file_path = os.path.join(root, file) |
| 17 | + relative_path = os.path.relpath(file_path, root_dir) |
| 18 | + if file.endswith('.py') and ".preview." not in file: |
| 19 | + ignore_file = any(pattern.search(relative_path) for pattern in exclude_patterns) |
| 20 | + if not ignore_file: |
| 21 | + py_files.append(relative_path) |
| 22 | + return py_files |
| 23 | + |
| 24 | +def execute_file(file_path): |
| 25 | + result = subprocess.run(['python', file_path], capture_output=True, text=True) |
| 26 | + return result.stdout, result.stderr, file_path |
| 27 | + |
| 28 | +def main(): |
| 29 | + files_to_execute = find_py_files(root_dir, exclude_patterns) |
| 30 | + print("Executing these python files:") |
| 31 | + print("\n".join(files_to_execute)) |
| 32 | + |
| 33 | + with ThreadPoolExecutor() as executor: |
| 34 | + futures = [executor.submit(execute_file, file) for file in files_to_execute] |
| 35 | + for future in futures: |
| 36 | + stdout, stderr, file_path = future.result() |
| 37 | + print(f'\nExecuting {file_path}:\n\n Output: \n\r {stdout}') |
| 38 | + if stderr: |
| 39 | + print(f'\nError from {file_path}:\n\n Error: {stderr}') |
| 40 | + |
| 41 | + |
| 42 | +if __name__ == "__main__": |
| 43 | + main() |
0 commit comments