Skip to content

Commit 8df408e

Browse files
authored
chore: add self-bootstraping uv run --script helper (#15092)
## Description If you try to use `scripts/run-tests` but you haven't installed `uv` then it isn't going to work. To help ease any onboarding for new users we added `scripts/uv-run-script` to use which will self-bootstrap `uv` first if it is not already installed. ## Testing <!-- Describe your testing strategy or note what tests are included --> ## Risks <!-- Note any risks associated with this change, or "None" if no risks --> ## Additional Notes <!-- Any other information that would be helpful for reviewers -->
1 parent 0b92c07 commit 8df408e

File tree

2 files changed

+54
-1
lines changed

2 files changed

+54
-1
lines changed

scripts/run-tests

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env uv run --script
1+
#!/usr/bin/env scripts/uv-run-script
22
# -*- mode: python -*-
33
# /// script
44
# requires-python = ">=3.8"

scripts/uv-run-script

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
# --- utility: ensure uv exists ---
5+
ensure_uv() {
6+
if command -v uv >/dev/null 2>&1; then
7+
return 0
8+
fi
9+
10+
# Common install locations
11+
local CANDIDATE_PATHS=(
12+
"$HOME/.local/bin"
13+
"$HOME/.cargo/bin"
14+
)
15+
16+
for path in "${CANDIDATE_PATHS[@]}"; do
17+
if [[ -x "$path/uv" ]]; then
18+
export PATH="$path:$PATH"
19+
return 0
20+
fi
21+
done
22+
23+
# Try to install if still missing
24+
echo "[uv-run-script] uv not found, installing..."
25+
if [[ "$OSTYPE" == "darwin"* ]] || command -v brew >/dev/null 2>&1; then
26+
echo "[uv-run-script] Installing via Homebrew..."
27+
brew install uv
28+
else
29+
echo "[uv-run-script] Installing via installer script..."
30+
curl -LsSf https://astral.sh/uv/install.sh | sh
31+
fi
32+
33+
# Recheck after install — maybe it landed in .local/bin
34+
for path in "${CANDIDATE_PATHS[@]}"; do
35+
if [[ -x "$path/uv" ]]; then
36+
export PATH="$path:$PATH"
37+
return 0
38+
fi
39+
done
40+
41+
echo "[uv-run-script] ERROR: uv installation failed or not found in PATH."
42+
return 1
43+
}
44+
45+
# --- main logic ---
46+
if ! ensure_uv; then
47+
exit 1
48+
fi
49+
50+
TARGET_SCRIPT="$1"
51+
shift
52+
53+
exec uv run --script "$TARGET_SCRIPT" "$@"

0 commit comments

Comments
 (0)