-
Notifications
You must be signed in to change notification settings - Fork 61
/
develop
executable file
·240 lines (192 loc) · 5.1 KB
/
develop
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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
#!/usr/bin/env bash
#
# install-cli
#
# Copy this file into your project to enable easy, guided
# installation/bootstrapping.
#
# Don't like sh/bash/etc? Sure.
#
# Love sh/bash/etc? Yeah, but....
#
# Let's use it here, to bootstrap whatever tools/libraries/etc. we
# *really* love for our project.
#
# You can name your implementation of this script whatever you like,
# such as: install
#
# Update INSTALL_VERSION to require the version of install-cli this
# script expects
INSTALL_VERSION=0.0.6
#
# start bootstrap installation lib
#
# This is a *bit* of boilerplate to ensure we've downloaded the correct
# version of install-cli. (You probably don't need to touch this.)
#
INSTALL_FILE=.install.${INSTALL_VERSION//./-}.bash.inc
INSTALL_URL=https://raw.githubusercontent.com/dssg/install-cli/$INSTALL_VERSION/install.bash.inc
[ -f $INSTALL_FILE ] || curl -#L $INSTALL_URL -o $INSTALL_FILE
. $INSTALL_FILE
#
# end bootstrap installation lib
#
#
# start project check/install
#
# pyenv
pyenv_bin="${PYENV_ROOT:-$HOME/.pyenv}/bin"
pyenv_homebrew_bin=/usr/local/bin
exists_pyenv_installer() {
[ -d "$pyenv_bin" ]
}
exists_pyenv_homebrew() {
[ -x "${pyenv_homebrew_bin}/pyenv" ]
}
exists_pyenv() {
exists_pyenv_installer || exists_pyenv_homebrew
}
boostrap_pyenv() {
if exists_pyenv_installer
then
export PATH="$pyenv_bin:$PATH"
elif exists_pyenv_homebrew
then
export PATH="$pyenv_homebrew_bin:$PATH"
fi
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"
}
install_pyenv() {
curl -#L https://github.com/pyenv/pyenv-installer/raw/master/bin/pyenv-installer | bash
boostrap_pyenv # bootstrap for subsequent commands
}
require pyenv \
exists_pyenv \
install_pyenv \
--fail-prefix="not found"
if exists_pyenv
then
echo
icli::set_context pyenv
if icli::check_command pyenv
then
icli::message "${T_FGREEN}initialized ✓"
else
icli::message "${T_FRED}not set up ✗"
icli::message
icli::message "${T_FYELLOW}hint: add the following lines to your .bashrc, .bash_profile or .zshenv, $(tput sitm)etc."
icli::message
icli::message '\texport PATH="~/.pyenv/bin:$PATH"'
icli::message '\teval "$(pyenv init -)"'
icli::message '\teval "$(pyenv virtualenv-init -)"'
icli::message
icli::message "${T_FMAGENTA}reference: https://github.com/pyenv/pyenv"
icli::message "${T_FMAGENTA}reference: https://github.com/pyenv/pyenv-installer/"
boostrap_pyenv # bootstrap for subsequent commands
fi
icli::unset_context
fi
# python
version_info=$(<.python-version.current)
py_version="${version_info#*-}"
which_python() {
local py_version="$1"
local installed_info
local python_exe="python${py_version}"
while true; do
if icli::check_command $python_exe || [ $python_exe = python ]; then
break
else
# strip a version part from the exe
# NOTE: must support POSIX sed (not just GNU)
python_exe="$(<<<"$python_exe" sed -Ee 's/\.{0,1}[0-9]{1,}$//')"
fi
done
installed_info="$($python_exe --version 2>/dev/null)"
if icli::check_command $python_exe && [ -z "$installed_info" ]; then
# python <3.4 printed version to stderr
installed_info="$($python_exe --version 2>&1)"
fi
if [ "${installed_info#* }" = "$py_version" ]; then
echo $python_exe
return 0
else
return 1
fi
}
exists_python() {
if icli::check_command pyenv; then
pyenv versions 2> /dev/null | grep -E "^ *${py_version}$" > /dev/null
else
# check if installed globally or via an active virtual environment
which_python $py_version > /dev/null
fi
}
install_python() {
pyenv install -s $py_version
}
require "python-${py_version}" \
exists_python \
install_python \
--fail-prefix="v${py_version} not found"
# virtualenv
exists_virtualenv() {
pyenv versions 2> /dev/null | grep "$version_info" > /dev/null
}
install_virtualenv() {
pyenv virtualenv $py_version $version_info
}
if icli::check_command pyenv
then
require virtualenv \
exists_virtualenv \
install_virtualenv \
"pyenv project virtual environment \"$version_info\" not found"
else
echo
icli::set_context virtualenv
icli::message "${T_FYELLOW}pyenv required – will not install ✗"
icli::unset_context
fi
# auto-activation
exists_symlink() {
[[ "$(readlink .python-version)" = .python-version.current ]]
}
create_symlink() {
ln -is .python-version.current .python-version
}
if exists_virtualenv
then
require activation \
exists_symlink \
create_symlink \
"file .python-version not configured to activate \"$version_info\""
else
echo
icli::set_context activation
icli::message "${T_FYELLOW}pyenv-virtualenv required – will not install ✗"
icli::unset_context
fi
# python libs
install_lib() {
pip install \
-r requirement/test.txt \
-r requirement/dev.txt
}
# no great (easy) way to check that all python libs installed;
# rather, always fail check and let pip figure it out
require libs \
icli::always_install \
install_lib
# triage
exists_triage() {
pip show triage &> /dev/null
}
install_triage() {
pip install -e ".[rq]"
}
require triage \
exists_triage \
install_triage \
"development library not found"