Skip to content

Commit a649bff

Browse files
committed
feat: add automated dependency lock generation script (pylock_generator.sh)
1 parent bccfcb6 commit a649bff

File tree

1 file changed

+153
-0
lines changed

1 file changed

+153
-0
lines changed

scripts/pylocks_generator.sh

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
# ----------------------------
5+
# CONFIGURATION
6+
# ----------------------------
7+
CPU_INDEX="--index-url=https://console.redhat.com/api/pypi/public-rhai/rhoai/3.0/cpu-ubi9/simple/"
8+
CUDA_INDEX="--index-url=https://console.redhat.com/api/pypi/public-rhai/rhoai/3.0/cuda-ubi9/simple/"
9+
ROCM_INDEX="--index-url=https://console.redhat.com/api/pypi/public-rhai/rhoai/3.0/rocm-ubi9/simple/"
10+
11+
MAIN_DIRS=("jupyter" "runtimes" "rstudio" "codeserver")
12+
13+
# ----------------------------
14+
# HELPER FUNCTIONS
15+
# ----------------------------
16+
info() { echo -e "🔹 \033[1;34m$1\033[0m"; }
17+
warn() { echo -e "⚠️ \033[1;33m$1\033[0m"; }
18+
error() { echo -e "❌ \033[1;31m$1\033[0m"; }
19+
ok() { echo -e "✅ \033[1;32m$1\033[0m"; }
20+
21+
# ----------------------------
22+
# PRE-FLIGHT CHECK
23+
# ----------------------------
24+
if ! command -v uv &>/dev/null; then
25+
error "uv command not found. Please install uv: https://github.com/astral-sh/uv"
26+
exit 1
27+
fi
28+
29+
# ----------------------------
30+
# GET TARGET DIRECTORIES
31+
# ----------------------------
32+
if [ $# -gt 0 ]; then
33+
TARGET_DIRS=("$1")
34+
else
35+
info "Scanning main directories for Python projects..."
36+
TARGET_DIRS=()
37+
for base in "${MAIN_DIRS[@]}"; do
38+
if [ -d "$base" ]; then
39+
while IFS= read -r -d '' pyproj; do
40+
TARGET_DIRS+=("$(dirname "$pyproj")")
41+
done < <(find "$base" -type f -name "pyproject.toml" -print0)
42+
fi
43+
done
44+
fi
45+
46+
if [ ${#TARGET_DIRS[@]} -eq 0 ]; then
47+
error "No directories containing pyproject.toml were found."
48+
exit 1
49+
fi
50+
51+
# ----------------------------
52+
# MAIN LOOP
53+
# ----------------------------
54+
FAILED_DIRS=()
55+
SUCCESS_DIRS=()
56+
57+
for TARGET_DIR in "${TARGET_DIRS[@]}"; do
58+
echo
59+
echo "==================================================================="
60+
info "Processing directory: $TARGET_DIR"
61+
echo "==================================================================="
62+
63+
cd "$TARGET_DIR" || continue
64+
mkdir -p uv.lock
65+
PYTHON_VERSION="${PWD##*-}"
66+
67+
# Detect available Dockerfiles (flavors)
68+
HAS_CPU=false
69+
HAS_CUDA=false
70+
HAS_ROCM=false
71+
[ -f "Dockerfile.cpu" ] && HAS_CPU=true
72+
[ -f "Dockerfile.cuda" ] && HAS_CUDA=true
73+
[ -f "Dockerfile.rocm" ] && HAS_ROCM=true
74+
75+
if ! $HAS_CPU && ! $HAS_CUDA && ! $HAS_ROCM; then
76+
warn "No Dockerfiles found in $TARGET_DIR (cpu/cuda/rocm). Skipping."
77+
cd - >/dev/null
78+
continue
79+
fi
80+
81+
echo "📦 Python version: $PYTHON_VERSION"
82+
echo "🧩 Detected flavors:"
83+
$HAS_CPU && echo " • CPU"
84+
$HAS_CUDA && echo " • CUDA"
85+
$HAS_ROCM && echo " • ROCm"
86+
echo
87+
88+
DIR_SUCCESS=true
89+
90+
run_lock() {
91+
local flavor="$1"
92+
local index="$2"
93+
local output="uv.lock/pylock.${flavor}.toml"
94+
95+
echo "➡️ Generating ${flavor^^} lock file..."
96+
set +e
97+
uv pip compile pyproject.toml \
98+
--output-file "$output" \
99+
--format pylock.toml \
100+
--generate-hashes \
101+
--emit-index-url \
102+
--python-version="$PYTHON_VERSION" \
103+
--python-platform linux \
104+
--no-annotate \
105+
$index
106+
local status=$?
107+
set -e
108+
109+
if [ $status -ne 0 ]; then
110+
warn "${flavor^^} lock failed in $TARGET_DIR"
111+
rm -f "$output"
112+
DIR_SUCCESS=false
113+
else
114+
ok "${flavor^^} lock generated successfully."
115+
fi
116+
}
117+
118+
$HAS_CPU && run_lock "cpu" "$CPU_INDEX"
119+
$HAS_CUDA && run_lock "cuda" "$CUDA_INDEX"
120+
$HAS_ROCM && run_lock "rocm" "$ROCM_INDEX"
121+
122+
if $DIR_SUCCESS; then
123+
SUCCESS_DIRS+=("$TARGET_DIR")
124+
else
125+
FAILED_DIRS+=("$TARGET_DIR")
126+
fi
127+
128+
cd - >/dev/null
129+
done
130+
131+
# ----------------------------
132+
# SUMMARY
133+
# ----------------------------
134+
echo
135+
echo "==================================================================="
136+
ok "Lock generation complete."
137+
echo "==================================================================="
138+
139+
if [ ${#SUCCESS_DIRS[@]} -gt 0 ]; then
140+
echo "✅ Successfully generated locks for:"
141+
for d in "${SUCCESS_DIRS[@]}"; do
142+
echo "$d"
143+
done
144+
fi
145+
146+
if [ ${#FAILED_DIRS[@]} -gt 0 ]; then
147+
echo
148+
warn "Failed lock generation for:"
149+
for d in "${FAILED_DIRS[@]}"; do
150+
echo "$d"
151+
echo "Please comment out the missing package to continue and report the missing package to aipcc"
152+
done
153+
fi

0 commit comments

Comments
 (0)