-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·272 lines (232 loc) · 7.46 KB
/
Copy pathsetup.sh
File metadata and controls
executable file
·272 lines (232 loc) · 7.46 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
#!/usr/bin/env bash
# ──────────────────────────────────────────────────────────────
# NewsReX Environment Setup
# Interactive installer — arrow keys to navigate, Enter to select.
# ──────────────────────────────────────────────────────────────
set -euo pipefail
# ── Colors & symbols ─────────────────────────────────────────
BOLD="\033[1m"
DIM="\033[2m"
CYAN="\033[36m"
GREEN="\033[32m"
YELLOW="\033[33m"
MAGENTA="\033[35m"
RESET="\033[0m"
CHECK="${GREEN}✓${RESET}"
ARROW="${CYAN}❯${RESET}"
HIDE_CURSOR="\033[?25l"
SHOW_CURSOR="\033[?25h"
# Restore cursor on exit
trap 'printf "${SHOW_CURSOR}"' EXIT
# ── Helpers ──────────────────────────────────────────────────
banner() {
echo ""
echo -e "${BOLD}${CYAN}"
cat << 'EOF'
_ __ ____ _ __
/ | / /__ _ _____| _ \ ___ | |/ /
/ |/ / _ \ \ /\ / / __| |_) / _ \| /
/ /| / __/\ V V /\__ \ _ < __/| \
/_/ |_/\___| \_/\_/ |___/_| \_\___||_|\_\
EOF
echo -e "${RESET}"
echo -e " ${DIM}Modular News Recommendation Research Framework${RESET}"
echo ""
}
separator() {
echo -e "${DIM} ────────────────────────────────────────────${RESET}"
}
# Interactive arrow-key menu.
# $1 = prompt
# $2 = default index (0-based)
# $3+ = "label|description" pairs
#
# Sets global REPLY to the chosen label.
pick() {
local prompt="$1"; shift
local selected="$1"; shift
local -a items=("$@")
local count=${#items[@]}
# Parse labels and descriptions
local -a labels=()
local -a descs=()
for item in "${items[@]}"; do
labels+=("${item%%|*}")
descs+=("${item#*|}")
done
printf "\n"
printf " ${BOLD}${prompt}${RESET} ${DIM}(↑/↓ to move, Enter to select)${RESET}\n"
printf "\n"
# Hide cursor during selection
printf "${HIDE_CURSOR}"
# Draw menu
_draw_menu() {
local i
for ((i = 0; i < count; i++)); do
if ((i == selected)); then
printf " ${ARROW} ${BOLD}${CYAN}%-10s${RESET} ${DIM}%s${RESET}\n" "${labels[$i]}" "${descs[$i]}"
else
printf " ${DIM}%-10s %s${RESET}\n" "${labels[$i]}" "${descs[$i]}"
fi
done
}
# Move cursor up N lines
_move_up() {
printf "\033[%dA" "$1"
}
_draw_menu
while true; do
# Read a single keypress
IFS= read -rsn1 key || true
# Arrow keys send escape sequences: ESC [ A/B
if [[ "$key" == $'\x1b' ]]; then
read -rsn2 -t 0.1 rest || true
case "$rest" in
"[A") # Up
((selected > 0)) && ((selected--)) || true
;;
"[B") # Down
((selected < count - 1)) && ((selected++)) || true
;;
esac
elif [[ "$key" == "" ]]; then
# Enter pressed
break
elif [[ "$key" == "k" ]]; then
((selected > 0)) && ((selected--)) || true
elif [[ "$key" == "j" ]]; then
((selected < count - 1)) && ((selected++)) || true
fi
# Redraw
_move_up "$count"
_draw_menu
done
printf "${SHOW_CURSOR}"
# Replace menu with the confirmed selection
_move_up "$count"
local i
for ((i = 0; i < count; i++)); do
printf "\033[2K" # clear line
if ((i == 0)); then
printf " ${CHECK} ${BOLD}${GREEN}%s${RESET} ${DIM}%s${RESET}\n" "${labels[$selected]}" "${descs[$selected]}"
else
printf "\n"
fi
done
# Move cursor back up past the blank lines
if ((count > 1)); then
_move_up $((count - 1))
# Clear the blank lines by moving down and clearing
for ((i = 1; i < count; i++)); do
printf "\033[1B\033[2K"
done
# Position cursor after the selection line
_move_up $((count - 1))
printf "\033[1B"
fi
REPLY="${labels[$selected]}"
}
# Interactive yes/no with arrow keys
yesno() {
local prompt="$1"
local default="${2:-1}" # 0=yes, 1=no
local selected=$default
printf "\n"
printf "${HIDE_CURSOR}"
_draw_yesno() {
printf "\r\033[2K"
if ((selected == 0)); then
printf " ${BOLD}%s${RESET} ${CYAN}❯ ${BOLD}Yes${RESET} ${DIM}No${RESET}" "$prompt"
else
printf " ${BOLD}%s${RESET} ${DIM}Yes${RESET} ${CYAN}❯ ${BOLD}No${RESET}" "$prompt"
fi
}
_draw_yesno
while true; do
IFS= read -rsn1 key || true
if [[ "$key" == $'\x1b' ]]; then
read -rsn2 -t 0.1 rest || true
case "$rest" in
"[C"|"[D") # Left/Right arrow
selected=$(( (selected + 1) % 2 ))
;;
esac
elif [[ "$key" == "h" || "$key" == "l" ]]; then
selected=$(( (selected + 1) % 2 ))
elif [[ "$key" == "y" || "$key" == "Y" ]]; then
selected=0; break
elif [[ "$key" == "n" || "$key" == "N" ]]; then
selected=1; break
elif [[ "$key" == "" ]]; then
break
fi
_draw_yesno
done
printf "${SHOW_CURSOR}"
# Replace with confirmed answer
printf "\r\033[2K"
if ((selected == 0)); then
printf " ${BOLD}%s${RESET} ${CHECK} ${GREEN}Yes${RESET}\n" "$prompt"
return 0
else
printf " ${BOLD}%s${RESET} ${CHECK} No\n" "$prompt"
return 1
fi
}
# ── Main ─────────────────────────────────────────────────────
banner
EXTRAS=()
# 1. Framework
pick "Framework" 0 \
"keras|Keras 3 (JAX/Torch backend)" \
"jax|JAX + Flax NNX" \
"pytorch|PyTorch" \
"all|All frameworks"
FRAMEWORK="$REPLY"
separator
# 2. CUDA
pick "CUDA version" 0 \
"none|CPU only / macOS" \
"cu118|CUDA 11.8" \
"cu124|CUDA 12.4" \
"cu126|CUDA 12.6" \
"cu130|CUDA 13.0"
CUDA="$REPLY"
separator
# Build extras from selections
if [[ "$CUDA" == "none" ]]; then
if [[ "$FRAMEWORK" == "all" ]]; then
EXTRAS+=("all")
else
EXTRAS+=("$FRAMEWORK")
fi
else
EXTRAS+=("$CUDA")
case "$FRAMEWORK" in
all) EXTRAS+=("all-${CUDA}");;
keras) EXTRAS+=("keras");;
jax) EXTRAS+=("jax" "jax-cuda");;
pytorch) ;; # cu* extra already includes torch
esac
fi
# 3. Optional tools
if yesno "Modal (remote GPU training)?" 1; then
EXTRAS+=("modal")
fi
if yesno "Dev tools (pytest, ruff, mypy)?" 1; then
EXTRAS+=("dev")
fi
# ── Run ──────────────────────────────────────────────────────
CMD="uv sync"
for e in "${EXTRAS[@]}"; do
CMD+=" --extra $e"
done
echo ""
separator
echo ""
echo -e " ${ARROW} ${BOLD}Running:${RESET} ${MAGENTA}${CMD}${RESET}"
echo ""
eval "$CMD"
echo ""
echo -e " ${CHECK} ${BOLD}${GREEN}Setup complete!${RESET}"
echo ""