generated from CS3219-AY2324S1/course-assessment-template
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathcheck_format.sh
32 lines (25 loc) · 856 Bytes
/
check_format.sh
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
#!/bin/bash
# Use the provided PYTHON_PATH or default to the system's Python
PYTHON_PATH="${PYTHON_PATH:-$(which python)}"
# Run formatter commands in the background and collect their PIDs
$PYTHON_PATH -m autoflake --check "$@" &
pid_autoflake=$!
$PYTHON_PATH -m black --check "$@" &
pid_black=$!
$PYTHON_PATH -m isort --check-only "$@" &
pid_isort=$!
# Store all the PIDs in an array
pids=($pid_autoflake $pid_black $pid_isort)
# Function to kill all running jobs
kill_jobs() {
echo "An error occurred. Exiting and killing background jobs..."
kill "${pids[@]}" 2>/dev/null
}
# Trap signals and errors to cleanup background jobs
trap 'kill_jobs; exit 1;' ERR SIGINT SIGTERM
# Wait for all jobs to complete and exit if any fails
for pid in "${pids[@]}"; do
wait "$pid" || { kill_jobs; exit 1; }
done
echo "All formatting checks passed."
exit 0