forked from readbeyond/aeneas
-
Notifications
You must be signed in to change notification settings - Fork 0
/
manage_venvs.sh
executable file
·291 lines (257 loc) · 6.92 KB
/
manage_venvs.sh
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
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
#!/bin/bash
# __author__ = "Alberto Pettarin"
# __copyright__ = """
# Copyright 2012-2013, Alberto Pettarin (www.albertopettarin.it)
# Copyright 2013-2015, ReadBeyond Srl (www.readbeyond.it)
# Copyright 2015-2017, Alberto Pettarin (www.albertopettarin.it)
# """
# __license__ = "GNU AGPL 3"
# __version__ = "1.7.2"
# __email__ = "aeneas@readbeyond.it"
# __status__ = "Production"
usage() {
echo ""
echo "Usage: bash $0 [py2.7|py3.5|py3.6|pypy] [uninstall|install|deps|sdist|tests|full] [--no-numpy-upgrade]"
echo ""
}
uninstall() {
echo "[INFO] Removing venv $1 ..."
rm -rf "$1"
echo "[INFO] Removing venv $1 ... done"
}
create() {
if [ -e "$1" ]
then
echo "[INFO] venv $1 already exists."
echo "[INFO] Use 'uninstall' to remove it before reinstalling it."
else
echo "[INFO] Creating venv $1 ..."
# create virtualenv
virtualenv -p "$2" "$1"
# create output directory to run examples
mkdir $1/output
echo "[INFO] Creating venv $1 ... done"
fi
}
deps() {
if [ ! -e "$1" ]
then
echo "[INFO] venv $1 does not exist."
echo "[INFO] Use 'install' or 'full' to create it."
else
echo "[INFO] Installing Python dependencies in $1 ..."
cd $1
source bin/activate
pip install -U pip
if [ "$2" == "pypy" ]
then
# on pypy install cython and numpy from its devel repo
# as recommended in http://pypy.org/download.html
if [ "$3" -eq "1" ]
then
pip install -U cython git+https://github.com/numpy/numpy.git
else
#pip install cython git+https://github.com/numpy/numpy.git
echo "[INFO] Not upgrading numpy (switch --no-numpy-upgrade)"
fi
else
# otherwise, just install regular numpy
if [ "$3" -eq "1" ]
then
pip install -U numpy
else
#pip install numpy
echo "[INFO] Not upgrading numpy (switch --no-numpy-upgrade)"
fi
fi
pip install -U lxml BeautifulSoup4
pip install -U boto3 requests tgt youtube-dl
# NOTE Pillow might raise errors due to missing libraries
# (e.g., libjpeg, libpng, zlib)
# so install it as the last one
pip install -U Pillow
deactivate
cd ..
echo "[INFO] Installing Python dependencies in $1 ... done"
fi
}
sdist() {
#
# # check that we are running in a venv
# python -c 'import sys; sys.exit(0) if hasattr(sys, "real_prefix") else sys.exit(1)'
# if [ "$?" -eq 1 ]
# then
# # not in venv
# else
# # in venv
# fi
# echo ""
#
if [ ! -e "$1" ]
then
echo "[INFO] venv $1 does not exist."
echo "[INFO] Use 'install' or 'full' to create it."
else
cd $1
source bin/activate
echo "[INFO] Uninstalling aeneas..."
rm -f *.tar.gz
rm -rf output
mkdir output
pip uninstall aeneas -y
echo "[INFO] Uninstalling aeneas... done"
deactivate
cd ..
if [ "$2" == "--remove" ]
then
echo "[INFO] Uninstall only: returning."
return
fi
if [ "$2" != "" ]
then
if [ -e $2 ]
then
echo "[INFO] Copying file $2"
cp $2 $1
else
echo "[ERRO] File $2 not found, aborting!"
return
fi
else
if [ -e ../dist/*.tar.gz ]
then
echo "[INFO] Copying file from ../dist/"
cp ../dist/*.tar.gz $1
else
echo "[ERRO] No .tar.gz found in the dist/ directory, aborting!"
return
fi
fi
cd $1
source bin/activate
echo "[INFO] Installing aeneas..."
pip install numpy
pip install *.tar.gz
rm -f *.tar.gz
echo "[INFO] Installing aeneas... done"
echo "[INFO] Diagnostics..."
python -m aeneas.diagnostics
echo "[INFO] Diagnostics... done"
echo "[INFO] Testing CFW..."
python -c 'import aeneas.globalfunctions as gf; print(gf.can_run_c_extension("cfw"))'
echo "[INFO] Testing CFW... done"
deactivate
cd ..
fi
}
copytests() {
if [ ! -e "$1" ]
then
echo "[INFO] venv $1 does not exist."
echo "[INFO] Use 'install' or 'full' to create it."
else
echo "[INFO] Copying tests in $1 ..."
cd $1
source bin/activate
# delete old stuff, if any
rm -rf tests
mkdir tests
mkdir tests/output
# copy current code locally and set it up
cp -r ../../aeneas ../../setup.py ../../setupmeta.py ../../run_all_unit_tests.py tests/
cd tests
pip install numpy
OS=`uname`
if [ "$OS" == "Darwin" ]
then
# Mac OS X
# add /usr/local/lib to path, otherwise cew cannot be built
python setup.py build_ext --inplace --rpath=/usr/local/lib
else
# Linux
# espeak lib should be globally visible
python setup.py build_ext --inplace
fi
cd ..
deactivate
cd ..
echo "[INFO] Copying tests in $1 ... done"
fi
}
# check that we have at least two arguments,
# otherwise show usage and exit
if [ "$#" -lt 2 ]
then
usage
exit 1
fi
# get arguments
EX=$1
ACTION=$2
UPGRADENUMPY=1
for PARAM in $@
do
if [ "$PARAM" == "--no-numpy-upgrade" ]
then
UPGRADENUMPY=0
fi
done
# replace e.g. "venv_python2.7/", "venv_python2.7", "py2.7", "2.7" with "python2.7"
for V in "2.7" "3.5" "3.6" "py"
do
if [ "$EX" == "venv_python$V/" ] || [ "$EX" == "venv_python$V" ] || [ "$EX" == "py$V" ] || [ "$EX" == "$V" ]
then
if [ "$V" == "py" ]
then
EX="pypy"
else
EX="python$V"
fi
fi
done
# venv directory name
D="venv_$EX"
# check the full path of the executable
FULLEX=`which $EX`
if [ "$FULLEX" == "" ]
then
echo "[ERRO] Unable to find the full path of executable $EX, aborting."
exit 1
fi
# check the action argument
if [ "$ACTION" != "uninstall" ] && [ "$ACTION" != "install" ] && [ "$ACTION" != "deps" ] && [ "$ACTION" != "sdist" ] && [ "$ACTION" != "tests" ] && [ "$ACTION" != "full" ]
then
usage
exit 1
fi
if [ "$ACTION" == "uninstall" ]
then
uninstall $D
fi
if [ "$ACTION" == "install" ]
then
create $D $FULLEX
fi
if [ "$ACTION" == "deps" ]
then
deps $D $EX $UPGRADENUMPY
fi
if [ "$ACTION" == "sdist" ]
then
ARCHIVE=""
if [ "$#" -ge 3 ]
then
ARCHIVE=$3
fi
sdist $D $ARCHIVE $STOP
fi
if [ "$ACTION" == "tests" ]
then
copytests $D
fi
if [ "$ACTION" == "full" ]
then
create $D $FULLEX
deps $D $EX $UPGRADENUMPY
copytests $D
fi