-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.py
67 lines (50 loc) · 1.86 KB
/
run.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
from datetime import datetime
import subprocess
import os
import sys
import tomllib
def run_command(command):
try:
result = subprocess.run(command, check=True, text=True, capture_output=True)
return result.stdout
except subprocess.CalledProcessError as e:
print(f"Error running command: {' '.join(command)}")
print(e.stderr)
sys.exit(1)
def main():
print("Running `cargo test`...")
run_command(["cargo", "test"])
print("Running `cargo build`...")
run_command(["cargo", "build"])
# Create output directory
timestamp = datetime.now().strftime("%m%d%H%M")
output_dir_path = os.path.join("outputs", timestamp)
os.makedirs(output_dir_path, exist_ok=True)
print(f"Output to {output_dir_path}")
input_files_sorted = sorted(os.listdir("inputs"))
with open("Cargo.toml", "rb") as f:
data = tomllib.load(f)
binary_path = f"./target/debug/{data['package']['name']}"
for file_name in input_files_sorted:
input_path = os.path.join("inputs", file_name)
output_path = os.path.join(output_dir_path, file_name)
print(f"Processing {file_name}...")
try:
with open(input_path, "r") as infile, open(output_path, "w") as outfile:
result = subprocess.run(
[binary_path],
stdin=infile,
stdout=outfile,
stderr=subprocess.PIPE,
text=True,
)
if result.returncode != 0:
print(f"Error executing {binary_path} with {file_name}")
print(result.stderr)
sys.exit(1)
except Exception as e:
print(f"An unexpected error occurred: {e}")
sys.exit(1)
print("All files processed successfully.")
if __name__ == "__main__":
main()