-
Notifications
You must be signed in to change notification settings - Fork 167
/
install.sh
executable file
·104 lines (90 loc) · 3.58 KB
/
install.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
#!/bin/sh
PROG=$(basename $0)
lang_model_name=${SW_INSTALL_SPC_MODEL_NAME:-"en_core_web_lg"}
lang_model_name_dash=$(echo "$lang_model_name" | tr '_' '-')
if [ -f ".env" ]; then
echo "$PROG Install: .env found"
else
echo "$PROG Copying: .env.dist -> .env"
cp .env.dist .env
fi
if [ -f "db.sqlite3" ]; then
echo "$PROG Install: db.sqlite3 found"
else
echo "$PROG Copying: db.sqlite3.dist -> db.sqlite3"
cp db.sqlite3.dist db.sqlite3
fi
python swirl/banner.py
echo ""
echo "$PROG Installing dependencies:"
pip install --upgrade --no-cache-dir -r requirements.txt
echo "$PROG Checking for ${lang_model_name_dash}"
found_model=$(pip list 2>/dev/null | grep ${lang_model_name_dash} | awk '{print $1}')
if [ "x$found_model" = "x$lang_model_name_dash" ]; then
echo "$PROG Found $lang_model_name , checking freshness...."
# Check the version of the model and the software version of the spacy. If
# the software version is not in the range of the model software version,then
# down load the latest model.
model_sw_version=$(python -m spacy info ${lang_model_name} | grep '^spacy_version' | awk '{print $2}')
spacy_sw_version=$(pip show spacy | grep '^Version' | awk '{print $2}')
min_version=$(echo $model_sw_version | awk -F '[<,>,=]' '{print $3}')
max_version=$(echo $model_sw_version | awk -F '[<,>]' '{print $4}')
echo $PROG : model_sw_version:$model_sw_version spacy_sw_version:$spacy_sw_version min_version:$min_version max_version:$max_version
is_in_range=$(awk -v ver="$spacy_sw_version" -v min="$min_version" -v max="$max_version" 'BEGIN {
split(ver, arrVer, ".");
split(min, arrMin, ".");
split(max, arrMax, ".");
# Compare major versions
# model_sw_version:>=3.5.0,<3.6.0 spacy_sw_version:3.6.1 min_version:3.5.0 max_version:3.6.0
if (int(arrVer[1]) < int(arrMin[1]) || int(arrVer[1]) > int(arrMax[1])) {
print "false_M";
exit;
}
# If major version is equal to min major version, but minor version is out of range
if (int(arrVer[1]) == int(arrMin[1]) && int(arrVer[2]) < int(arrMin[2])) {
print "false_Ni";
exit;
}
# If minor version is equal to min minor version, but patch version is out of range
if (int(arrVer[2]) == int(arrMin[2]) && int(arrVer[3]) < int(arrMin[3])) {
print "false_Pi";
exit;
}
# If major version is equal to max major version, but minor version is out of range
if (int(arrVer[1]) == int(arrMax[1]) && int(arrVer[2]) > int(arrMax[2])) {
print "false_Nx";
exit;
}
# If minor version is equal to max minor version, but patch version is out of range
if (int(arrVer[2]) == int(arrMax[2]) && int(arrVer[3]) > int(arrMax[3])) {
print "false_Px";
exit;
}
# If everything is okay
print "true";
}')
if [ "$is_in_range" != "true" ]; then
do_download=0
else
do_download=1
fi
## Also check if pip thinks the model
pip list -o 2>/dev/null | grep ${lang_model_name}
pip_out_of_sync=$?
if [ $pip_out_of_sync -eq 0 ]; then
do_download=0
fi
echo $PROG : is_in_range:$is_in_range pip_out_of_sync:$pip_out_of_sync do_download:$do_download
if [ $do_download -eq 0 ]; then
echo "$PROG ${lang_model_name} is outdated. Downloading spacy ${lang_model_name}..."
python -m spacy download en_core_web_lg
else
echo "$PROG ${lang_model_name} is up to date, skipping download"
fi
else
echo "$PROG Downloading spacy ${lang_model_name}..."
python -m spacy download en_core_web_lg
fi
echo "$PROG Downloading NLTK modules..."
./download-nltk-resources.sh
echo "$PROG If no errors occurred, run python swirl.py setup"