-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup_env.sh
More file actions
executable file
·112 lines (93 loc) · 3.47 KB
/
setup_env.sh
File metadata and controls
executable file
·112 lines (93 loc) · 3.47 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
#!/usr/bin/env bash
set -Eeuo pipefail
# KuzuAlchemy Environment Setup
# Installs Python, Rust, and builds the rust extensions
# Usage:
# ./setup_env.sh [VENV] [TOOLS_DIR] [PY_SPEC]
# Defaults:
VENV="${1:-.venv}"
TOOLS_DIR="${2:-.tools}"
PY_SPEC="${3:-3.12}"
log(){ printf '[kuzualchemy] %s\n' "$*"; }
die(){ printf '[kuzualchemy] ERROR: %s\n' "$*" >&2; exit 1; }
have(){ command -v "$1" >/dev/null 2>&1; }
# CRITICAL: Save original directory BEFORE any cd operations
ORIGINAL_DIR="$(pwd -P)"
ROOT="$ORIGINAL_DIR"
TOOLS="$ROOT/$TOOLS_DIR"
UV_HOME="$TOOLS/uv"
PY_HOME="$TOOLS/python"
mkdir -p "$UV_HOME" "$PY_HOME"
# ---------------- 1) Install uv LOCALLY (no PATH/profile edits) ----------------
export UV_NO_MODIFY_PATH=1
export UV_UNMANAGED_INSTALL="$UV_HOME"
if have curl; then
log "Downloading uv (curl) -> $UV_HOME"
curl -LsSf https://astral.sh/uv/install.sh | sh
elif have wget; then
log "Downloading uv (wget) -> $UV_HOME"
wget -qO- https://astral.sh/uv/install.sh | sh
else
die "Need curl or wget to fetch uv."
fi
UV="$UV_HOME/uv"; [[ -x "$UV" ]] || UV="$UV_HOME/uv.exe"
[[ -x "$UV" ]] || die "uv not found in $UV_HOME"
# ---------------- 2) Install managed Python & create venv ----------------
export UV_PYTHON_INSTALL_DIR="$PY_HOME"
export UV_PYTHON_PREFERENCE="only-managed"
export UV_LINK_MODE="copy" # Avoid hardlink warnings on WSL2/cross-filesystem
log "Installing managed Python $PY_SPEC under $PY_HOME"
"$UV" python install "$PY_SPEC" --force >/dev/null
log "Creating venv $VENV (seed pip)"
# Always overwrite without prompting
if [[ -d "$VENV" ]]; then
log "Removing existing venv $VENV"
rm -rf "$VENV"
fi
"$UV" venv "$VENV" --python "$PY_SPEC" --seed
# Compute venv executables (Git Bash on Windows is reported as MINGW/MSYS/CYGWIN)
UNAME="$(uname -s || true)"
if [[ "$UNAME" == MINGW* || "$UNAME" == MSYS* || "$UNAME" == CYGWIN* || "${OS:-}" == "Windows_NT" ]]; then
VENV_PY="$ROOT/$VENV/Scripts/python.exe"
IS_WINDOWS=1
else
VENV_PY="$ROOT/$VENV/bin/python"
IS_WINDOWS=0
fi
# Verify Python executable exists
if [[ ! -f "$VENV_PY" ]]; then
die "venv python not found at $VENV_PY"
fi
# ---------------- 3) Install Python deps STRICTLY into the venv -------------
# Dependencies and wheels are now handled by pyproject.toml
log "Installing project and dependencies from pyproject.toml"
"$VENV_PY" -m pip install --upgrade pip setuptools wheel
"$VENV_PY" -m pip install -e ".[dev,test]"
# ---------------- 4) Final Verification ----------------
log "Verifying installation..."
# Test Python
if "$VENV_PY" -c "import sys; sys.exit(0)" 2>/dev/null; then
log "✓ Python is working ($VENV_PY)"
else
log "⚠ Python verification failed for $VENV_PY"
log " Checking if file exists: $([ -f "$VENV_PY" ] && echo "YES" || echo "NO")"
log " Trying to run with full error:"
"$VENV_PY" -c "import sys; print('Python OK'); sys.exit(0)" 2>&1 || true
fi
if "$VENV_PY" -c "import atp_pipeline, kuzualchemy; print('atp_pipeline:', atp_pipeline.__file__); print('kuzualchemy:', kuzualchemy.__file__)" >/dev/null; then
log "✓ atp_pipeline and kuzualchemy are importable"
else
die "Import check failed for atp_pipeline and/or kuzualchemy"
fi
echo
echo "=== KuzuAlchemy Environment Ready ==="
echo "venv: $ROOT/$VENV"
echo "python: $VENV_PY"
echo
echo "To activate:"
echo " source $ROOT/$VENV/bin/activate # Linux/Mac"
echo " $ROOT/$VENV/Scripts/activate # Windows"
echo
log "Setup complete!"
# Final safety check - make sure we're back in the original directory
cd "$ORIGINAL_DIR"