-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup-python312.sh
More file actions
executable file
·60 lines (49 loc) · 1.56 KB
/
setup-python312.sh
File metadata and controls
executable file
·60 lines (49 loc) · 1.56 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
#!/usr/bin/env bash
set -euo pipefail
FORCE=0
for arg in "$@"; do
case "$arg" in
--force) FORCE=1 ;;
esac
done
log() { echo "[setup-python312] $*"; }
die() { log "ERROR: $*"; exit 1; }
trap 'die "failed at line ${LINENO} (exit $?)"' ERR
if [[ "${EUID}" -eq 0 ]]; then
log "refusing to run as root/sudo. Run as a normal user; this step will use sudo internally as needed."
exit 1
fi
have_python312=0
if command -v python3.12 >/dev/null 2>&1; then
if python3.12 --version 2>/dev/null | grep -Eq '^Python 3\.12(\.|$)'; then
have_python312=1
fi
fi
if [[ "$FORCE" -ne 1 ]] && [[ "$have_python312" -eq 1 ]]; then
log "python3.12 already installed at: $(command -v python3.12). Skipping (use --force to re-run)."
exit 0
fi
if ! command -v uv >/dev/null 2>&1; then
die "uv is not installed. Run setup-uv.sh first."
fi
# uv installs managed Python executables into ~/.local/bin by default.
export PATH="$HOME/.local/bin:$PATH"
if [[ -f "$HOME/.local/bin/env" ]]; then
set +u
# shellcheck disable=SC1090
source "$HOME/.local/bin/env"
set -u
fi
log "installing Python 3.12 via uv"
if [[ "$FORCE" -eq 1 ]]; then
uv python install 3.12 --reinstall --default
else
uv python install 3.12 --default
fi
if ! command -v python3.12 >/dev/null 2>&1; then
die "Python 3.12 install completed but 'python3.12' is not on PATH. Try: source ~/.local/bin/env or source ~/.bashrc"
fi
if ! python3.12 --version 2>/dev/null | grep -Eq '^Python 3\.12(\.|$)'; then
die "python3.12 is present but does not report a 3.12 version"
fi
log "python3.12: $(python3.12 --version)"