-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup
More file actions
executable file
·107 lines (84 loc) · 2.15 KB
/
setup
File metadata and controls
executable file
·107 lines (84 loc) · 2.15 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
#!/usr/bin/env bash
set -euo pipefail
ROOT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"
cd "$ROOT_DIR"
bold() { printf "\033[1m%s\033[0m\n" "$*"; }
info() { printf "• %s\n" "$*"; }
fail() { printf "\nERROR: %s\n" "$*" >&2; exit 1; }
ensure_uv() {
if command -v uv >/dev/null 2>&1; then
info "uv found: $(command -v uv)"
return 0
fi
bold "uv not found; attempting install..."
if command -v brew >/dev/null 2>&1; then
info "Installing uv via Homebrew..."
brew install uv
return 0
fi
if command -v curl >/dev/null 2>&1; then
info "Installing uv via https://astral.sh/uv/install.sh ..."
curl -LsSf https://astral.sh/uv/install.sh | sh
export PATH="$HOME/.local/bin:$PATH"
return 0
fi
fail "uv is required but wasn't found. Install it (https://docs.astral.sh/uv/) and re-run ./setup"
}
ensure_git() {
if command -v git >/dev/null 2>&1; then
info "git found: $(command -v git)"
return 0
fi
bold "git not found; attempting install..."
if command -v brew >/dev/null 2>&1; then
info "Installing git via Homebrew..."
brew install git
return 0
fi
fail "git is required but wasn't found. Install git and re-run ./setup"
}
ensure_git_repo() {
if [[ -d ".git" ]]; then
info "git repo already initialized"
return 0
fi
bold "Initializing git repository..."
git init
}
ensure_venv() {
if [[ -d ".venv" ]]; then
info ".venv already exists"
return 0
fi
bold "Creating .venv..."
uv venv .venv
}
sync_deps() {
bold "Installing dependencies (including dev group)..."
# Prefer installing all dependency groups when supported; fall back as needed.
if uv sync --all-groups; then
return 0
fi
if uv sync --group dev; then
return 0
fi
fail "Failed to install dependencies via uv sync"
}
install_hooks() {
bold "Installing git hooks..."
if [[ -x "./setup-hooks" ]]; then
uv run ./setup-hooks
return 0
fi
fail "No hook installer script found (expected ./setup-hooks, ./setup-hooks.sh, or ./setup_hooks.sh)"
}
main() {
bold "Setup complete!"
ensure_uv
ensure_git
ensure_git_repo
ensure_venv
sync_deps
install_hooks
}
main "$@"