Repository navigation
Expand file tree
/
Copy pathquickstart.sh
More file actions
executable file
·131 lines (120 loc) · 6.06 KB
/
Copy pathquickstart.sh
File metadata and controls
executable file
·131 lines (120 loc) · 6.06 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
#!/usr/bin/env bash
# quickstart.sh — sage-examples dev environment setup
#
# Usage:
# ./quickstart.sh # dev mode (default): hooks + .[dev] (includes [full])
# ./quickstart.sh --full # optional backends only: .[full]
# ./quickstart.sh --standard # core deps only: no extras
# ./quickstart.sh --yes # non-interactive (assume yes)
# ./quickstart.sh --doctor # diagnose environment issues
#
# Install matrix:
# (default / --dev) pip install -e .[dev] ← includes [full] via self-ref
# --full pip install -e .[full]
# --standard pip install -e .
#
# Rules:
# - NEVER creates a new venv. Must be called in an existing non-venv environment.
# - Installs hooks via direct copy from hooks/.
set -e
# ─── Colors ─────────────────────────────────────────────────────────────────
RED='\033[0;31m'
YELLOW='\033[1;33m'
GREEN='\033[0;32m'
CYAN='\033[0;36m'
BLUE='\033[0;34m'
BOLD='\033[1m'
NC='\033[0m'
# ─── Arguments ────────────────────────────────────────────────────────────────
EXTRAS="[dev]" # default — dev includes [full] via pyproject self-reference
DOCTOR=false
for arg in "$@"; do
case "$arg" in
--doctor) DOCTOR=true ;;
--standard) EXTRAS="" ;;
--full) EXTRAS="[full]" ;;
--dev) EXTRAS="[dev]" ;;
--yes|-y) : ;;
esac
done
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$SCRIPT_DIR"
echo -e "${CYAN}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
echo -e "${BOLD}${BLUE} sage-examples — Quick Start${NC}"
echo -e "${CYAN}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
echo ""
# ─── Doctor ────────────────────────────────────────────────────────────────────
if [ "$DOCTOR" = true ]; then
echo -e "${BOLD}${BLUE}Environment Diagnosis${NC}"
echo ""
echo -e "${YELLOW}Python:${NC} $(python3 --version 2>/dev/null || echo 'NOT FOUND')"
echo -e "${YELLOW}Conda env:${NC} ${CONDA_DEFAULT_ENV:-none}"
echo -e "${YELLOW}Venv:${NC} ${VIRTUAL_ENV:-none}"
echo -e "${YELLOW}ruff:${NC} $(ruff --version 2>/dev/null || echo 'NOT FOUND')"
echo -e "${YELLOW}pytest:${NC} $(pytest --version 2>/dev/null || echo 'NOT FOUND')"
echo ""
echo -e "${YELLOW}Git hooks installed:${NC}"
for h in pre-commit pre-push post-commit; do
if [ -f "$PROJECT_ROOT/.git/hooks/$h" ]; then
echo -e " ${GREEN}✓ $h${NC}"
else
echo -e " ${RED}✗ $h${NC}"
fi
done
exit 0
fi
# ─── Step 0: Require an active non-venv environment ────────────────────────────
if [ -n "$VIRTUAL_ENV" ]; then
echo -e "${RED} ❌ Detected Python venv: $VIRTUAL_ENV${NC}"
echo -e "${YELLOW} → This repository forbids venv/.venv usage.${NC}"
echo -e "${YELLOW} → Please deactivate the venv and use Conda or a system Python.${NC}"
exit 1
fi
# ─── Step 1/3: Python version check ──────────────────────────────────────────────
echo -e "${YELLOW}${BOLD}Step 1/3: Checking Python environment${NC}"
PYTHON_VERSION=$(python3 -c "import sys; print(f'{sys.version_info.major}.{sys.version_info.minor}')" 2>/dev/null || echo "unknown")
echo -e " Python version: ${CYAN}${PYTHON_VERSION}${NC}"
if python3 -c "import sys; exit(0 if sys.version_info >= (3,10) else 1)" 2>/dev/null; then
echo -e " ${GREEN}✓ Python ≥ 3.10${NC}"
else
echo -e " ${RED}✗ Python 3.10+ required (found ${PYTHON_VERSION})${NC}"
exit 1
fi
echo ""
# ─── Step 2/3: Install Git Hooks ─────────────────────────────────────────────────
echo -e "${YELLOW}${BOLD}Step 2/3: Installing Git hooks${NC}"
if [ -d "$PROJECT_ROOT/hooks" ]; then
installed=0
for hook_src in "$PROJECT_ROOT/hooks"/*; do
hook_name=$(basename "$hook_src")
hook_dst="$PROJECT_ROOT/.git/hooks/$hook_name"
cp "$hook_src" "$hook_dst"
chmod +x "$hook_dst"
echo -e " ${GREEN}✓ $hook_name${NC}"
installed=$((installed + 1))
done
echo -e "${GREEN}✓ $installed hook(s) installed${NC}"
else
echo -e "${YELLOW}⚠ hooks/ directory not found — skipping${NC}"
fi
echo ""
# ─── Step 3/3: Install package ────────────────────────────────────────────────────
echo -e "${YELLOW}${BOLD}Step 3/3: Installing package (editable)${NC}"
if [ -n "$EXTRAS" ]; then
echo -e " ${CYAN}pip install -e .$EXTRAS${NC}"
pip install -e ".$EXTRAS"
else
echo -e " ${CYAN}pip install -e .${NC} (standard — no extras)"
pip install -e .
fi
echo -e "${GREEN}✓ Package installed in editable mode${EXTRAS:+ with extras: $EXTRAS}${NC}"
echo ""
echo -e "${GREEN}${BOLD}✓ Setup complete!${NC}"
echo ""
echo -e "${BLUE}${BOLD}Next steps:${NC}"
echo -e " ${CYAN}pytest tests/${NC} — run tests"
echo -e " ${CYAN}ruff check src/${NC} — lint"
echo -e " ${CYAN}./quickstart.sh --full${NC} — reinstall with optional backends"
echo -e " ${CYAN}./quickstart.sh --standard${NC} — install core deps only (no extras)"
echo -e " ${CYAN}./quickstart.sh --doctor${NC} — diagnose environment"
echo ""