-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathinit.sh
More file actions
executable file
·192 lines (172 loc) · 5.22 KB
/
init.sh
File metadata and controls
executable file
·192 lines (172 loc) · 5.22 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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
#!/usr/bin/env bash
set -euo pipefail
# ---------- 공통 유틸 ----------
color() { # $1=color_name, $2=message
case "${1:-}" in
blue) printf "\e[34m%s\e[0m\n" "$2" ;;
green) printf "\e[32m%s\e[0m\n" "$2" ;;
yellow) printf "\e[33m%s\e[0m\n" "$2" ;;
red) printf "\e[31m%s\e[0m\n" "$2" ;;
*) printf "%s\n" "$2" ;;
esac
}
find_python() {
if command -v python3 >/dev/null 2>&1; then
echo "python3"
elif command -v python >/dev/null 2>&1; then
echo "python"
else
color red "Python이 필요합니다. Python을 설치한 뒤 다시 실행하세요."
exit 1
fi
}
activate_venv() {
if [ -f ".venv/bin/activate" ]; then
# Linux/Mac
# shellcheck disable=SC1091
. ".venv/bin/activate"
elif [ -f ".venv/Scripts/activate" ]; then
# Windows (Git Bash)
# shellcheck disable=SC1091
. ".venv/Scripts/activate"
else
color red ".venv 활성화 스크립트를 찾을 수 없습니다."
exit 1
fi
}
setup_cuda_env() {
local os_name cuda_dir
os_name=$(uname -s 2>/dev/null || echo "UNKNOWN")
# nvcc 기준 탐색
if command -v nvcc >/dev/null 2>&1; then
cuda_dir=$(dirname "$(dirname "$(command -v nvcc)")")
fi
# 표준 경로 탐색 (Linux/Mac)
if [ -z "${cuda_dir:-}" ]; then
if [ -d "/usr/local/cuda" ]; then
cuda_dir="/usr/local/cuda"
else
# 가장 높은 버전 선택
local candidate
candidate=$(ls -d /usr/local/cuda-* 2>/dev/null | sort -V | tail -n1 || true)
if [ -n "${candidate}" ]; then
cuda_dir="${candidate}"
fi
fi
fi
# Windows (Git Bash) 경로 탐색
if [ -z "${cuda_dir:-}" ] && [ -d "/c/Program Files/NVIDIA GPU Computing Toolkit/CUDA" ]; then
local win_base win_candidate
win_base="/c/Program Files/NVIDIA GPU Computing Toolkit/CUDA"
win_candidate=$(ls -d "${win_base}"/v* 2>/dev/null | sort -V | tail -n1 || true)
if [ -n "${win_candidate}" ]; then
cuda_dir="${win_candidate}"
fi
fi
if [ -z "${cuda_dir:-}" ]; then
color yellow "CUDA를 찾을 수 없습니다. CUDA 관련 설정을 건너뛰고 계속 진행합니다."
return 0
fi
export CUDA_HOME="${cuda_dir}"
export CUDA_PATH="${cuda_dir}"
export PATH="${cuda_dir}/bin:${PATH}"
# 라이브러리 경로 설정 (플랫폼별)
if [ -d "${cuda_dir}/lib64" ]; then
export LD_LIBRARY_PATH="${cuda_dir}/lib64:${LD_LIBRARY_PATH:-}"
elif [ -d "${cuda_dir}/lib" ]; then
export LD_LIBRARY_PATH="${cuda_dir}/lib:${LD_LIBRARY_PATH:-}"
fi
# macOS 호환
if [ -d "${cuda_dir}/lib" ]; then
export DYLD_LIBRARY_PATH="${cuda_dir}/lib:${DYLD_LIBRARY_PATH:-}"
fi
color green "CUDA 설정 완료: ${cuda_dir}"
}
ensure_uv() {
if command -v uv >/dev/null 2>&1; then
color blue "uv가 이미 설치되어 있습니다."
return 0
fi
color blue "uv 설치 중..."
pip install -U uv >/dev/null 2>&1 || {
color red "uv 설치에 실패했습니다."
exit 1
}
color green "uv 설치 완료"
}
# ---------- 0. .venv 세팅 후 venv 활성화 ----------
if [ ! -d ".venv" ]; then
if command -v python >/dev/null 2>&1; then
color blue ".venv 생성 중...(python)"
python -m venv .venv
else
color blue ".venv 생성 중...(python3)"
if command -v python3 >/dev/null 2>&1; then
python3 -m venv .venv
else
color red "Python이 필요합니다. Python을 설치한 뒤 다시 실행하세요."
exit 1
fi
fi
color green ".venv 생성 완료"
fi
activate_venv
color green "가상환경 활성화 완료"
# ---------- 1. CUDA 환경 세팅 (없으면 종료) ----------
setup_cuda_env
# ---------- 2. uv 설치 및 requirements 설치 ----------
ensure_uv
# uv sync (pyproject 기반 설치). uv.lock이 있으면 --frozen 사용
if [ -f "pyproject.toml" ]; then
color blue "uv sync 실행 중..."
if [ -f "uv.lock" ]; then
uv sync --frozen || {
color red "uv sync(--frozen) 실패";
exit 1
}
else
uv sync || {
color red "uv sync 실패";
exit 1
}
fi
color green "uv sync 완료"
else
# pyproject가 없으면 requirements.txt로 설치
if [ -f "requirements.txt" ]; then
color blue "requirements.txt 기반 설치 진행 (uv pip)"
uv pip install -r requirements.txt || {
color red "requirements 설치 실패";
exit 1
}
color green "requirements 설치 완료"
fi
fi
# ---------- 3. 기존 설정 유지: git / pre-commit ----------
# git 설정
git config --global commit.template ./.commit_template || true
git config --global core.editor "code --wait" || true
color blue "Fin git config"
# pre-commit 설정
# 1) pip 최신화 및 설치 시도 (uv가 있으면 uv 우선)
python -m pip install --upgrade pip setuptools wheel >/dev/null 2>&1 || true
if command -v uv >/dev/null 2>&1; then
uv pip install -U pre-commit >/dev/null 2>&1 || true
else
python -m pip install -U pre-commit >/dev/null 2>&1 || true
fi
# 2) 설치 검증 후만 실행
if python - <<'PY'
import sys
try:
import pre_commit # noqa: F401
except Exception:
sys.exit(1)
PY
then
python -m pre_commit autoupdate || true
python -m pre_commit install || true
color blue "Fin pre-commit"
else
color yellow "pre-commit 설치를 확인하지 못했습니다. pre-commit 단계를 건너뜁니다."
fi