forked from libtcod/python-tcod
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall_python.sh
More file actions
executable file
·239 lines (218 loc) · 7.74 KB
/
install_python.sh
File metadata and controls
executable file
·239 lines (218 loc) · 7.74 KB
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
#!/bin/bash
# *********************
# Copyright and License
# *********************
# The multibuild package, including all examples, code snippets and attached
# documentation is covered by the 2-clause BSD license.
# Copyright (c) 2013-2016, Matt Terry and Matthew Brett; all rights
# reserved.
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
# 1. Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
# IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
set -e
# Work round bug in travis xcode image described at
# https://github.com/direnv/direnv/issues/210
shell_session_update() { :; }
MACPYTHON_URL=https://www.python.org/ftp/python
PYPY_URL=https://downloads.python.org/pypy
MACPYTHON_PY_PREFIX=/Library/Frameworks/Python.framework/Versions
WORKING_SDIR=working
DOWNLOADS_SDIR=/tmp
function untar {
local in_fname=$1
if [ -z "$in_fname" ];then echo "in_fname not defined"; exit 1; fi
local extension=${in_fname##*.}
case $extension in
tar) tar -xf $in_fname ;;
gz|tgz) tar -zxf $in_fname ;;
bz2) tar -jxf $in_fname ;;
zip) unzip $in_fname ;;
xz) unxz -c $in_fname | tar -xf ;;
*) echo Did not recognize extension $extension; exit 1 ;;
esac
}
function lex_ver {
# Echoes dot-separated version string padded with zeros
# Thus:
# 3.2.1 -> 003002001
# 3 -> 003000000
echo $1 | awk -F "." '{printf "%03d%03d%03d", $1, $2, $3}'
}
function unlex_ver {
# Reverses lex_ver to produce major.minor.micro
# Thus:
# 003002001 -> 3.2.1
# 003000000 -> 3.0.0
echo "$((10#${1:0:3}+0)).$((10#${1:3:3}+0)).$((10#${1:6:3}+0))"
}
function strip_ver_suffix {
echo $(unlex_ver $(lex_ver $1))
}
function check_var {
if [ -z "$1" ]; then
echo "required variable not defined"
exit 1
fi
}
function pyinst_ext_for_version {
# echo "pkg" or "dmg" depending on the passed Python version
# Parameters
# $py_version (python version in major.minor.extra format)
#
# Earlier Python installers are .dmg, later are .pkg.
local py_version=$1
check_var $py_version
local py_0=${py_version:0:1}
if [ $py_0 -eq 2 ]; then
if [ "$(lex_ver $py_version)" -ge "$(lex_ver 2.7.9)" ]; then
echo "pkg"
else
echo "dmg"
fi
elif [ $py_0 -ge 3 ]; then
if [ "$(lex_ver $py_version)" -ge "$(lex_ver 3.4.2)" ]; then
echo "pkg"
else
echo "dmg"
fi
fi
}
function get_pypy_build_prefix {
# gets the file prefix of the pypy.org PyPy2
#
# Parameters:
# $version : pypy2 version number
local version=$1
if [[ $version =~ ([0-9]+)\.([0-9]+) ]]; then
local major=${BASH_REMATCH[1]}
local minor=${BASH_REMATCH[2]}
if (( $major > 5 || ($major == 5 && $minor >= 3) )); then
echo "pypy2-v"
else
echo "pypy-"
fi
else
echo "error: expected version number, got $1" 1>&2
exit 1
fi
}
function get_pypy3_build_prefix {
# gets the file prefix of the pypy.org PyPy3
#
# Parameters:
# $version : pypy3 version number
local version=$1
if [[ $version =~ ([0-9]+)\.([0-9]+) ]]; then
local major=${BASH_REMATCH[1]}
local minor=${BASH_REMATCH[2]}
if (( $major == 5 && $minor <= 5 )); then
echo "pypy3.3-v"
elif (( $major < 5 )); then
echo "pypy3-"
else
echo "pypy3-v"
fi
else
echo "error: expected version number, got $1" 1>&2
exit 1
fi
}
function install_python {
# Picks an implementation of Python determined by the current enviroment
# variables then installs it
# Sub-function will set $PYTHON_EXE variable to the python executable
if [ -n "$MB_PYTHON_VERSION" ]; then
install_macpython $MB_PYTHON_VERSION
elif [ -n "$PYPY_VERSION" ]; then
install_mac_pypy $PYPY_VERSION
elif [ -n "$PYPY3_VERSION" ]; then
install_mac_pypy3 $PYPY3_VERSION
elif [ -z "$BREW_PYTHON3" ]; then
# Default Python install is missing virtualenv.
python -m ensurepip
python -m pip install virtualenv
fi
}
function install_macpython {
# Installs Python.org Python
# Parameter $version
# Version given in major or major.minor or major.minor.micro e.g
# "3" or "3.4" or "3.4.1".
# sets $PYTHON_EXE variable to python executable
local py_version=$1
local py_stripped=$(strip_ver_suffix $py_version)
local inst_ext=$(pyinst_ext_for_version $py_version)
local py_inst=python-$py_version-macosx10.9.$inst_ext
local inst_path=$DOWNLOADS_SDIR/$py_inst
mkdir -p $DOWNLOADS_SDIR
wget -nv $MACPYTHON_URL/$py_stripped/${py_inst} -P $DOWNLOADS_SDIR
if [ "$inst_ext" == "dmg" ]; then
hdiutil attach $inst_path -mountpoint /Volumes/Python
inst_path=/Volumes/Python/Python.mpkg
fi
sudo installer -pkg $inst_path -target /
local py_mm=${py_version:0:3}
PYTHON_EXE=$MACPYTHON_PY_PREFIX/$py_mm/bin/python$py_mm
# Install certificates for Python 3.6
local inst_cmd="/Applications/Python ${py_mm}/Install Certificates.command"
if [ -e "$inst_cmd" ]; then
sh "$inst_cmd"
fi
}
function install_mac_pypy {
# Installs pypy.org PyPy
# Parameter $version
# Version given in full major.minor.micro e.g "3.4.1".
# sets $PYTHON_EXE variable to python executable
local py_version=$1
local py_build=$(get_pypy_build_prefix $py_version)$py_version-osx64
local py_zip=$py_build.tar.bz2
local zip_path=$DOWNLOADS_SDIR/$py_zip
mkdir -p $DOWNLOADS_SDIR
wget -nv $PYPY_URL/${py_zip} -P $DOWNLOADS_SDIR
untar $zip_path
PYTHON_EXE=$(realpath $py_build/bin/pypy)
}
function install_mac_pypy3 {
# Installs pypy.org PyPy3
# Parameter $version
# Version given in full major.minor.micro e.g "3.4.1".
# sets $PYTHON_EXE variable to python executable
local py_version=$1
local py_build=$py_version-osx64
local py_zip=$py_build.tar.bz2
local zip_path=$DOWNLOADS_SDIR/$py_zip
mkdir -p $DOWNLOADS_SDIR
wget -nv $PYPY_URL/${py_zip} -P $DOWNLOADS_SDIR
mkdir -p $py_build
tar -xjf $zip_path -C $py_build --strip-components=1
PYTHON_EXE=$(realpath $py_build/bin/pypy3)
}
if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then
install_python
if [[ -n "$PYTHON_EXE" ]]; then
# Default Python install is missing virtualenv.
$PYTHON_EXE -m ensurepip
$PYTHON_EXE -m pip install --upgrade pip virtualenv
$PYTHON_EXE -m virtualenv venv -p $PYTHON_EXE
else
virtualenv venv
fi
source venv/bin/activate
fi