-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathrun_benchmarks
More file actions
executable file
·79 lines (65 loc) · 2.5 KB
/
run_benchmarks
File metadata and controls
executable file
·79 lines (65 loc) · 2.5 KB
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
68
69
70
71
72
73
74
75
76
77
78
79
#!/bin/bash
# Wrapper script for run_benchmarks.py with automatic venv management
set -e # Exit on error
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
VENV_DIR="$SCRIPT_DIR/.venv"
REQUIREMENTS_FILE="$SCRIPT_DIR/requirements.txt"
REQUIREMENTS_HASH_FILE="$VENV_DIR/.requirements_hash"
PYTHON_SCRIPT="$SCRIPT_DIR/run_benchmarks.py"
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Function to calculate hash of requirements.txt
get_requirements_hash() {
if [[ -f "$REQUIREMENTS_FILE" ]]; then
if command -v md5sum >/dev/null 2>&1; then
md5sum "$REQUIREMENTS_FILE" | cut -d' ' -f1
elif command -v md5 >/dev/null 2>&1; then
md5 -q "$REQUIREMENTS_FILE"
else
# Fallback to modification time if no hash command available
stat -f "%m" "$REQUIREMENTS_FILE" 2>/dev/null || stat -c "%Y" "$REQUIREMENTS_FILE" 2>/dev/null || echo "0"
fi
else
echo "no_requirements"
fi
}
# Function to check if requirements have changed
requirements_changed() {
if [[ ! -f "$REQUIREMENTS_HASH_FILE" ]]; then
return 0 # No hash file means requirements changed (or first run)
fi
current_hash=$(get_requirements_hash)
stored_hash=$(cat "$REQUIREMENTS_HASH_FILE" 2>/dev/null || echo "")
[[ "$current_hash" != "$stored_hash" ]]
}
# Create venv if it doesn't exist
if [[ ! -d "$VENV_DIR" ]]; then
echo -e "${YELLOW}Creating Python virtual environment...${NC}"
python3 -m venv "$VENV_DIR"
echo -e "${GREEN}Virtual environment created.${NC}"
fi
# Activate venv
source "$VENV_DIR/bin/activate"
# Check if requirements have changed and install/update if needed
if requirements_changed; then
echo -e "${YELLOW}Requirements have changed. Installing/updating dependencies...${NC}"
# Upgrade pip first
pip install --upgrade pip >/dev/null 2>&1
if [[ -f "$REQUIREMENTS_FILE" ]]; then
pip install -r "$REQUIREMENTS_FILE"
# Store the new hash
get_requirements_hash > "$REQUIREMENTS_HASH_FILE"
echo -e "${GREEN}Dependencies installed successfully.${NC}"
else
echo -e "${YELLOW}No requirements.txt found. Skipping dependency installation.${NC}"
fi
else
echo -e "${GREEN}Dependencies are up to date.${NC}"
fi
# Run the Python script with all arguments passed to this wrapper
echo -e "${GREEN}Running benchmark script...${NC}"
echo "----------------------------------------"
python "$PYTHON_SCRIPT" "$@"