-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpre-flight
142 lines (111 loc) · 3.12 KB
/
pre-flight
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
#!/usr/bin/env bash
# shellcheck disable=SC1091,SC2059,SC2086
#
# Activates the test environment, installing dependencies, and updating tests
# and dependencies. Even though bash is specified above (for shellcheck), this
# activation script should work for both BASH and ZSH.
#
function in-virtualenv() {
if [[ "${VIRTUAL_ENV-}" != "" ]]; then
true; return
else
false; return
fi
}
function has-virtualenv() {
if test -d ./venv; then
true
else
false
fi
}
function create-virtualenv() {
python3 -m venv venv
}
function activate-virtualenv() {
source venv/bin/activate
}
function switch-directory() {
# Script source both BASH and ZSH
local source="${BASH_SOURCE:-${(%):-%x}}"
# If the source is relative, prefix with the current directory
if [[ $source != /* ]]; then
source="$PWD/$source"
fi
local parent
parent="$(dirname "$source")"
if ! cd "$parent"; then
echo "Could not switch to $parent"
false; return
fi
if ! test -e './pre-flight'; then
echo "Could not switch to $parent"
false; return
fi
true; return
}
function is-supported-python() {
local major
major="$(python3 -c 'import sys; print(sys.version_info[0])')"
local minor
minor="$(python3 -c 'import sys; print(sys.version_info[1])')"
if (( major < 3 )); then
echo "Python $major.$minor is too old, please use 3.6+"
false; return
fi
if (( minor < 6 )); then
echo "Python $major.$minor is too old, please use 3.6+"
false; return
fi
if ! python3 -c "import ssl" > /dev/null; then
echo "Your Python setup does not support SSL. Please reinstall Python."
false; return
fi
true; return
}
function is-git-clean() {
if git diff-index --quiet HEAD; then
true
else
false
fi
}
function activate-acceptance-tests() {
local gc='\e[0;32m' # green
local bc='\e[1;34m' # blue
local nc='\e[0m' # reset
local doing='*'
local done="${gc}✓${nc}"
printf "Preparing test-environment for cloudscale.ch acceptance tests…\n\n"
if ! is-supported-python; then
return
fi
if ! switch-directory; then
return
fi
if ! has-virtualenv; then
printf "%b Creating virtual environment\r" "$doing"
create-virtualenv
printf "%b Created virtual environment \n" "$done"
fi
if ! in-virtualenv; then
activate-virtualenv
fi
printf "%b Updating tests\r" "$doing"
git pull -q
printf "%b Updated tests \n" "$done"
printf "%b Updating requirements\r" "$doing"
pip install --upgrade pip -q
pip install -r requirements.txt --upgrade -q
printf "%b Updated requirements \n\n" "$done"
if ! test -e ./private; then
printf "Please enter your cloudscale.ch API token: "
read -s -r token
printf "\n\n"
printf "export CLOUDSCALE_API_TOKEN=%s\n" "$token" > private
fi
chmod 0600 private
source private
printf "You are now ready to test by typing %b\n\n" "${bc}py.test${nc}"
}
activate-acceptance-tests