forked from HypothesisWorks/hypothesis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathensure-python.sh
executable file
·66 lines (54 loc) · 2.03 KB
/
ensure-python.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
#!/usr/bin/env bash
set -o errexit
set -o nounset
set -x
HERE="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
# shellcheck source=tooling/scripts/common.sh
source "$HERE/common.sh"
# This is to guard against multiple builds in parallel. The various installers will tend
# to stomp all over each other if you do this and they haven't previously successfully
# succeeded. We use a lock file to block progress so only one install runs at a time.
# This script should be pretty fast once files are cached, so the loss of concurrency
# is not a major problem.
# This should be using the lockfile command, but that's not available on the
# containerized travis and we can't install it without sudo.
# It is unclear if this is actually useful. I was seeing behaviour that suggested
# concurrent runs of the installer, but I can't seem to find any evidence of this lock
# ever not being acquired.
VERSION="$1"
TARGET=$(pythonloc "$VERSION")
if [ ! -e "$TARGET/bin/python" ] ; then
mkdir -p "$BASE"
LOCKFILE="$BASE/.install-lockfile"
while true; do
if mkdir "$LOCKFILE" 2>/dev/null; then
echo "Successfully acquired installer."
break
else
echo "Failed to acquire lock. Is another installer running? Waiting a bit."
fi
sleep $(( ( RANDOM % 10 ) + 1 )).$(( RANDOM % 100 ))s
if (( $(date '+%s') > 300 + $(stat --format=%X "$LOCKFILE") )); then
echo "We've waited long enough"
rm -rf "$LOCKFILE"
fi
done
trap 'rm -rf $LOCKFILE' EXIT
if [ ! -d "$PYENV/.git" ]; then
rm -rf "$PYENV"
git clone https://github.com/yyuu/pyenv.git "$PYENV"
else
back=$PWD
cd "$PYENV"
git fetch || echo "Update failed to complete. Ignoring"
git reset --hard origin/master
cd "$back"
fi
for _ in $(seq 5); do
if "$BASE/pyenv/plugins/python-build/bin/python-build" "$VERSION" "$TARGET" ; then
exit 0
fi
echo "Command failed. Retrying..."
sleep $(( ( RANDOM % 10 ) + 1 )).$(( RANDOM % 100 ))s
done
fi