-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.sh
More file actions
213 lines (176 loc) · 7.66 KB
/
setup.sh
File metadata and controls
213 lines (176 loc) · 7.66 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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
#!/bin/bash
# SAM-Batcher setup script with environment management
# Function to check if command exists
command_exists() {
command -v "$1" >/dev/null 2>&1
}
# Check if Python is available
if ! command_exists python3 && ! command_exists python; then
echo "Python not found! Please install Python 3.8 or newer."
exit 1
fi
# Check if we're in a virtual environment already
in_venv=0
if [ -n "$VIRTUAL_ENV" ]; then
echo "Already in a virtual environment: $VIRTUAL_ENV"
in_venv=1
fi
# Check if we're in a conda environment
in_conda=0
if [ -n "$CONDA_PREFIX" ]; then
echo "Already in a conda environment: $CONDA_PREFIX"
in_conda=1
fi
# Handle environment selection/creation
if [ $in_venv -eq 1 ] || [ $in_conda -eq 1 ]; then
echo "You are already in an environment."
read -p "Use current environment? (y/n): " use_current
if [ "$use_current" = "y" ]; then
echo "Using current environment."
else
# Choose which type of environment to use
read -p "Create/select a different environment? (venv/conda): " env_type
if [ "$env_type" = "venv" ]; then
read -p "Enter path for virtual environment (or leave empty for ./venv): " venv_path
venv_path=${venv_path:-"./venv"}
if [ -d "$venv_path" ]; then
echo "Virtual environment exists at $venv_path"
read -p "Use existing environment? (y/n): " use_existing
if [ "$use_existing" != "y" ]; then
echo "Creating new virtual environment at $venv_path..."
python3 -m venv "$venv_path" || python -m venv "$venv_path"
fi
else
echo "Creating new virtual environment at $venv_path..."
python3 -m venv "$venv_path" || python -m venv "$venv_path"
fi
# Activate the virtual environment
source "$venv_path/bin/activate"
# Verify activation
if [ -z "$VIRTUAL_ENV" ]; then
echo "Failed to activate virtual environment."
echo "Please manually activate it with:"
echo " source $venv_path/bin/activate"
echo "Then run:"
echo " python setup.py"
exit 1
fi
echo "Activated virtual environment at $venv_path"
elif [ "$env_type" = "conda" ]; then
if ! command_exists conda; then
echo "Conda not found. Please install Conda first."
exit 1
fi
read -p "Enter conda environment name (or leave empty for sam-batcher): " conda_env
conda_env=${conda_env:-"sam-batcher"}
if conda info --envs | grep -q "$conda_env"; then
echo "Conda environment $conda_env exists"
read -p "Use existing environment? (y/n): " use_existing
if [ "$use_existing" != "y" ]; then
echo "Creating new conda environment $conda_env..."
conda create -y -n "$conda_env" python=3.10
fi
else
echo "Creating new conda environment $conda_env..."
conda create -y -n "$conda_env" python=3.10
fi
# Try to activate the conda environment
echo "Attempting to activate conda environment $conda_env..."
# Try different activation methods
if command_exists conda; then
# Try to initialize conda for the shell
eval "$(conda shell.bash hook 2>/dev/null)" || true
conda activate "$conda_env" 2>/dev/null || true
fi
# Verify activation
if [ -z "$CONDA_PREFIX" ]; then
echo "Failed to activate conda environment."
echo "Please manually activate it with:"
echo " conda activate $conda_env"
echo "Then run:"
echo " python setup.py"
exit 1
fi
echo "Activated conda environment: $CONDA_PREFIX"
else
echo "Invalid environment type. Exiting."
exit 1
fi
fi
else
# No environment active, ask to create one
read -p "No environment active. Create one? (venv/conda/none): " env_type
if [ "$env_type" = "venv" ]; then
read -p "Enter path for virtual environment (or leave empty for ./venv): " venv_path
venv_path=${venv_path:-"./venv"}
if [ -d "$venv_path" ]; then
echo "Virtual environment exists at $venv_path"
read -p "Use existing environment? (y/n): " use_existing
if [ "$use_existing" != "y" ]; then
echo "Creating new virtual environment at $venv_path..."
python3 -m venv "$venv_path" || python -m venv "$venv_path"
fi
else
echo "Creating new virtual environment at $venv_path..."
python3 -m venv "$venv_path" || python -m venv "$venv_path"
fi
# Activate the virtual environment
source "$venv_path/bin/activate"
# Verify activation
if [ -z "$VIRTUAL_ENV" ]; then
echo "Failed to activate virtual environment."
echo "Please manually activate it with:"
echo " source $venv_path/bin/activate"
echo "Then run:"
echo " python setup.py"
exit 1
fi
echo "Activated virtual environment at $venv_path"
elif [ "$env_type" = "conda" ]; then
if ! command_exists conda; then
echo "Conda not found. Please install Conda first."
exit 1
fi
read -p "Enter conda environment name (or leave empty for sam-batcher): " conda_env
conda_env=${conda_env:-"sam-batcher"}
if conda info --envs | grep -q "$conda_env"; then
echo "Conda environment $conda_env exists"
read -p "Use existing environment? (y/n): " use_existing
if [ "$use_existing" != "y" ]; then
echo "Creating new conda environment $conda_env..."
conda create -y -n "$conda_env" python=3.10
fi
else
echo "Creating new conda environment $conda_env..."
conda create -y -n "$conda_env" python=3.10
fi
# Try to activate the conda environment
echo "Attempting to activate conda environment $conda_env..."
# Try different activation methods
if command_exists conda; then
# Try to initialize conda for the shell
eval "$(conda shell.bash hook 2>/dev/null)" || true
conda activate "$conda_env" 2>/dev/null || true
fi
# Verify activation
if [ -z "$CONDA_PREFIX" ]; then
echo "Failed to activate conda environment."
echo "Please manually activate it with:"
echo " conda activate $conda_env"
echo "Then run:"
echo " python setup.py"
exit 1
fi
echo "Activated conda environment: $CONDA_PREFIX"
elif [ "$env_type" != "none" ]; then
echo "Invalid environment type. Proceeding without an environment."
fi
fi
# Check if git is available
if ! command_exists git; then
echo "Git not found! Please install Git to use the setup script."
exit 1
fi
# Run the setup.py script which will handle submodule cloning and installation
python setup.py
echo "Setup completed successfully!"