forked from ray-project/ray
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install-dependencies.sh
executable file
·394 lines (342 loc) · 14.2 KB
/
install-dependencies.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
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
#!/usr/bin/env bash
# Push caller's shell options (quietly)
{ SHELLOPTS_STACK="${SHELLOPTS_STACK-}|$(set +o); set -$-"; } 2> /dev/null
set -euxo pipefail
ROOT_DIR=$(builtin cd "$(dirname "${BASH_SOURCE:-$0}")"; pwd)
WORKSPACE_DIR="${ROOT_DIR}/../.."
pkg_install_helper() {
case "${OSTYPE}" in
darwin*)
brew install "$@"
;;
linux*)
sudo apt-get install -qq -o=Dpkg::Use-Pty=0 "$@" | {
grep --line-buffered -v "^\(Preparing to unpack\|Unpacking\|Processing triggers for\) "
}
;;
*) false;;
esac
}
install_bazel() {
if command -v bazel; then
if [[ -n "${BUILDKITE-}" ]]; then
# Only reinstall Bazel if we need to upgrade to a different version.
python="$(command -v python3 || command -v python || echo python)"
current_version="$(bazel --version | grep -o "[0-9]\+.[0-9]\+.[0-9]\+")"
new_version="$("${python}" -s -c "import runpy, sys; runpy.run_path(sys.argv.pop(), run_name='__api__')" bazel_version "${ROOT_DIR}/../../python/setup.py")"
if [[ "$current_version" == "$new_version" ]]; then
echo "Bazel of the same version already exists, skipping the install"
return
fi
fi
fi
"${ROOT_DIR}"/install-bazel.sh
if [ -f /etc/profile.d/bazel.sh ]; then
. /etc/profile.d/bazel.sh
fi
}
install_base() {
if [ -n "${BUILDKITE-}" ]; then
echo "Skipping install_base in Buildkite"
return
fi
case "${OSTYPE}" in
linux*)
# Expired apt key error: https://github.com/bazelbuild/bazel/issues/11470#issuecomment-633205152
curl -f -s -L -R https://bazel.build/bazel-release.pub.gpg | sudo apt-key add - || true
sudo apt-get update -qq
pkg_install_helper build-essential curl unzip libunwind-dev python3-pip python3-setuptools \
tmux gdb
if [ "${LINUX_WHEELS-}" = 1 ]; then
pkg_install_helper docker
if [ -n "${TRAVIS-}" ]; then
sudo usermod -a -G docker travis
fi
fi
if [ -n "${PYTHON-}" ]; then
"${ROOT_DIR}/install-strace.sh" || true
fi
;;
esac
}
install_miniconda() {
if [ "${OSTYPE}" = msys ]; then
# Windows is on GitHub Actions, whose built-in Python installations we added direct support for.
python --version
return 0
fi
local conda="${CONDA_EXE-}" # Try to get the activated conda executable
if [ -z "${conda}" ]; then # If no conda is found, try to find it in PATH
conda="$(command -v conda || true)"
fi
if [ ! -x "${conda}" ]; then # If no conda is found, install it
local miniconda_dir # Keep directories user-independent, to help with Bazel caching
case "${OSTYPE}" in
linux*) miniconda_dir="/opt/miniconda";;
darwin*) miniconda_dir="/usr/local/opt/miniconda";;
msys) miniconda_dir="${ALLUSERSPROFILE}\Miniconda3";; # Avoid spaces; prefer the default path
esac
local miniconda_version="Miniconda3-py37_4.9.2" miniconda_platform="" exe_suffix=".sh"
case "${OSTYPE}" in
linux*) miniconda_platform=Linux;;
darwin*) miniconda_platform=MacOSX;;
msys*) miniconda_platform=Windows; exe_suffix=".exe";;
esac
case "${OSTYPE}" in
# The hosttype variable is deprecated.
darwin*) HOSTTYPE="x86_64";;
esac
local miniconda_url="https://repo.continuum.io/miniconda/${miniconda_version}-${miniconda_platform}-${HOSTTYPE}${exe_suffix}"
local miniconda_target="${HOME}/${miniconda_url##*/}"
curl -f -s -L -o "${miniconda_target}" "${miniconda_url}"
chmod +x "${miniconda_target}"
case "${OSTYPE}" in
msys*)
# We set /AddToPath=0 because
# (1) it doesn't take care of the current shell, and
# (2) it's consistent with -b in the UNIX installers.
MSYS2_ARG_CONV_EXCL="*" "${miniconda_target}" \
/RegisterPython=0 /AddToPath=0 /InstallationType=AllUsers /S /D="${miniconda_dir}"
conda="${miniconda_dir}\Scripts\conda.exe"
;;
*)
mkdir -p -- "${miniconda_dir}"
# We're forced to pass -b for non-interactive mode.
# Unfortunately it inhibits PATH modifications as a side effect.
"${WORKSPACE_DIR}"/ci/suppress_output "${miniconda_target}" -f -b -p "${miniconda_dir}"
conda="${miniconda_dir}/bin/conda"
;;
esac
fi
if [ ! -x "${CONDA_PYTHON_EXE-}" ]; then # If conda isn't activated, activate it
local restore_shell_state=""
if [ -o xtrace ]; then set +x && restore_shell_state="set -x"; fi # Disable set -x (noisy here)
# TODO(mehrdadn): conda activation is buggy on MSYS2; it adds C:/... to PATH,
# which gets split on a colon. Is it necessary to work around this?
eval "$("${conda}" shell."${SHELL##*/}" hook)" # Activate conda
conda init "${SHELL##*/}" # Add to future shells
${restore_shell_state} # Restore set -x
fi
local python_version
python_version="$(python -s -c "import sys; print('%s.%s' % sys.version_info[:2])")"
if [ -n "${PYTHON-}" ] && [ "${PYTHON}" != "${python_version}" ]; then # Update Python version
(
set +x
echo "Updating Anaconda Python ${python_version} to ${PYTHON}..."
"${WORKSPACE_DIR}"/ci/suppress_output conda install -q -y python="${PYTHON}"
)
fi
command -V python
test -x "${CONDA_PYTHON_EXE}" # make sure conda is activated
}
install_shellcheck() {
local shellcheck_version="0.7.1"
if [ "${shellcheck_version}" != "$(command -v shellcheck > /dev/null && shellcheck --version | sed -n "s/version: //p")" ]; then
local osname=""
case "${OSTYPE}" in
linux*) osname="linux";;
darwin*) osname="darwin";;
esac
local name="shellcheck-v${shellcheck_version}"
if [ "${osname}" = linux ] || [ "${osname}" = darwin ]; then
sudo mkdir -p /usr/local/bin || true
curl -f -s -L "https://github.com/koalaman/shellcheck/releases/download/v${shellcheck_version}/${name}.${osname}.x86_64.tar.xz" | {
sudo tar -C /usr/local/bin -x -v -J --strip-components=1 "${name}/shellcheck"
}
else
mkdir -p /usr/local/bin
curl -f -s -L -o "${name}.zip" "https://github.com/koalaman/shellcheck/releases/download/v${shellcheck_version}/${name}.zip"
unzip "${name}.zip" "${name}.exe"
mv -f "${name}.exe" "/usr/local/bin/shellcheck.exe"
fi
test "${shellcheck_version}" = "$(shellcheck --version | sed -n "s/version: //p")"
fi
}
install_linters() {
pip install -r "${WORKSPACE_DIR}"/python/requirements_linters.txt
install_shellcheck
}
install_nvm() {
local NVM_HOME="${HOME}/.nvm"
if [ "${OSTYPE}" = msys ]; then
local ver="1.1.7"
if [ ! -f "${NVM_HOME}/nvm.sh" ]; then
mkdir -p -- "${NVM_HOME}"
export NVM_SYMLINK="${PROGRAMFILES}\nodejs"
(
cd "${NVM_HOME}"
local target="./nvm-${ver}.zip"
curl -f -s -L -o "${target}" \
"https://github.com/coreybutler/nvm-windows/releases/download/${ver}/nvm-noinstall.zip"
unzip -q -- "${target}"
rm -f -- "${target}"
printf "%s\r\n" "root: $(cygpath -w -- "${NVM_HOME}")" "path: ${NVM_SYMLINK}" > settings.txt
)
printf "%s\n" \
"export NVM_HOME=\"$(cygpath -w -- "${NVM_HOME}")\"" \
"nvm() { \"\${NVM_HOME}/nvm.exe\" \"\$@\"; }" \
> "${NVM_HOME}/nvm.sh"
fi
elif [ -n "${BUILDKITE-}" ]; then
echo "Skipping nvm on Buildkite because we will use apt-get."
else
test -f "${NVM_HOME}/nvm.sh" # double-check NVM is already available on other platforms
fi
}
install_upgrade_pip() {
local python=python
if command -v python3 > /dev/null; then
python=python3
fi
if "${python}" -m pip --version || "${python}" -m ensurepip; then # Configure pip if present
"${python}" -m pip install --quiet pip==21.0.1
# If we're in a CI environment, do some configuration
if [ "${CI-}" = true ]; then
"${python}" -W ignore -m pip config -q --user set global.disable-pip-version-check True
"${python}" -W ignore -m pip config -q --user set global.no-color True
"${python}" -W ignore -m pip config -q --user set global.progress_bar off
"${python}" -W ignore -m pip config -q --user set global.quiet True
fi
"${python}" -m ensurepip
fi
}
install_node() {
if [ "${OSTYPE}" = msys ] ; then
{ echo "WARNING: Skipping running Node.js due to incompatibilities with Windows"; } 2> /dev/null
return
fi
if [ -n "${BUILDKITE-}" ] ; then
if [[ "${OSTYPE}" = darwin* ]]; then
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash
else
# https://github.com/nodesource/distributions/blob/master/README.md#installation-instructions
curl -sL https://deb.nodesource.com/setup_14.x | sudo -E bash -
sudo apt-get install -y nodejs
return
fi
fi
# Install the latest version of Node.js in order to build the dashboard.
(
set +x # suppress set -x since it'll get very noisy here
. "${HOME}/.nvm/nvm.sh"
nvm install node
nvm use --silent node
npm config set loglevel warn # make NPM quieter
)
}
install_toolchains() {
if [ -z "${BUILDKITE-}" ]; then
"${ROOT_DIR}"/install-toolchains.sh
fi
}
download_mnist() {
mkdir -p "${HOME}/data"
curl -o "${HOME}/data/mnist.zip" https://ray-ci-mnist.s3-us-west-2.amazonaws.com/mnist.zip
unzip "${HOME}/data/mnist.zip" -d "${HOME}/data"
}
install_dependencies() {
install_bazel
install_base
install_toolchains
install_upgrade_pip
if [ -n "${PYTHON-}" ] || [ "${LINT-}" = 1 ]; then
install_miniconda
# Upgrade the miniconda pip.
install_upgrade_pip
fi
install_nvm
if [ -n "${PYTHON-}" ] || [ -n "${LINT-}" ] || [ "${MAC_WHEELS-}" = 1 ]; then
install_node
fi
# Install modules needed in all jobs.
alias pip="python -m pip"
pip install --no-clean dm-tree==0.1.5 # --no-clean is due to: https://github.com/deepmind/tree/issues/5
if [ -n "${PYTHON-}" ]; then
# Remove this entire section once Serve dependencies are fixed.
if [ "${DOC_TESTING-}" != 1 ] && [ "${SGD_TESTING-}" != 1 ] && [ "${TUNE_TESTING-}" != 1 ] && [ "${RLLIB_TESTING-}" != 1 ]; then
# PyTorch is installed first since we are using a "-f" directive to find the wheels.
# We want to install the CPU version only.
local torch_url="https://download.pytorch.org/whl/torch_stable.html"
case "${OSTYPE}" in
darwin*) pip install torch torchvision;;
*) pip install torch==1.8.1+cpu torchvision==0.9.1+cpu -f "${torch_url}";;
esac
fi
# Try n times; we often encounter OpenSSL.SSL.WantReadError (or others)
# that break the entire CI job: Simply retry installation in this case
# after n seconds.
local status="0";
local errmsg="";
for _ in {1..3}; do
errmsg=$(CC=gcc pip install -r "${WORKSPACE_DIR}"/python/requirements.txt 2>&1) && break;
status=$errmsg && echo "'pip install ...' failed, will retry after n seconds!" && sleep 30;
done
if [ "$status" != "0" ]; then
echo "${status}" && return 1
fi
fi
# Default requirements
pip install -r "${WORKSPACE_DIR}"/python/requirements/requirements_default.txt
if [ "${LINT-}" = 1 ]; then
install_linters
# readthedocs has an antiquated build env.
# This is a best effort to reproduce it locally to avoid doc build failures and hidden errors.
local python_version
python_version="$(python -s -c "import sys; print('%s.%s' % sys.version_info[:2])")"
if [ "${OSTYPE}" = msys ] && [ "${python_version}" = "3.8" ]; then
{ echo "WARNING: Pillow binaries not available on Windows; cannot build docs"; } 2> /dev/null
else
pip install --use-deprecated=legacy-resolver -r "${WORKSPACE_DIR}"/doc/requirements-rtd.txt
pip install --use-deprecated=legacy-resolver -r "${WORKSPACE_DIR}"/doc/requirements-doc.txt
fi
fi
# Additional RLlib test dependencies.
if [ "${RLLIB_TESTING-}" = 1 ] || [ "${DOC_TESTING-}" = 1 ]; then
pip install -r "${WORKSPACE_DIR}"/python/requirements/rllib/requirements_rllib.txt
# install the following packages for testing on travis only
pip install 'recsim>=0.2.4'
fi
# Additional Tune/SGD/Doc test dependencies.
if [ "${TUNE_TESTING-}" = 1 ] || [ "${SGD_TESTING-}" = 1 ] || [ "${DOC_TESTING-}" = 1 ]; then
pip install -r "${WORKSPACE_DIR}"/python/requirements/tune/requirements_tune.txt
download_mnist
fi
# For Tune, install upstream dependencies.
if [ "${TUNE_TESTING-}" = 1 ] || [ "${DOC_TESTING-}" = 1 ]; then
pip install -r "${WORKSPACE_DIR}"/python/requirements/tune/requirements_upstream.txt
fi
# Data processing test dependencies.
if [ "${DATA_PROCESSING_TESTING-}" = 1 ] || [ "${DOC_TESTING-}" = 1 ]; then
pip install -r "${WORKSPACE_DIR}"/python/requirements/data_processing/requirements.txt
fi
if [ "${DATA_PROCESSING_TESTING-}" = 1 ]; then
pip install -r "${WORKSPACE_DIR}"/python/requirements/data_processing/requirements_dataset.txt
fi
# Remove this entire section once Serve dependencies are fixed.
if [ "${DOC_TESTING-}" != 1 ] && [ "${SGD_TESTING-}" != 1 ] && [ "${TUNE_TESTING-}" != 1 ] && [ "${RLLIB_TESTING-}" != 1 ]; then
# If CI has deemed that a different version of Torch
# should be installed, then upgrade/downgrade to that specific version.
if [ -n "${TORCH_VERSION-}" ]; then
case "${TORCH_VERSION-1.8.1}" in
1.8.1) TORCHVISION_VERSION=0.9.1;;
1.5) TORCHVISION_VERSION=0.6.0;;
*) TORCHVISION_VERSION=0.5.0;;
esac
pip install --use-deprecated=legacy-resolver --upgrade torch=="${TORCH_VERSION-1.8.1}" torchvision=="${TORCHVISION_VERSION}"
fi
fi
# RLlib testing with TF 1.x.
if [ "${RLLIB_TESTING-}" = 1 ] && { [ -n "${TF_VERSION-}" ] || [ -n "${TFP_VERSION-}" ]; }; then
pip install --upgrade tensorflow-probability=="${TFP_VERSION}" tensorflow=="${TF_VERSION}" gym
fi
# Additional Tune dependency for Horovod.
# This must be run last (i.e., torch cannot be re-installed after this)
if [ "${INSTALL_HOROVOD-}" = 1 ]; then
# TODO: eventually pin this to master.
HOROVOD_WITH_GLOO=1 HOROVOD_WITHOUT_MPI=1 HOROVOD_WITHOUT_MXNET=1 pip install -U git+https://github.com/horovod/horovod.git
fi
CC=gcc pip install psutil setproctitle==1.2.2 colorama --target="${WORKSPACE_DIR}/python/ray/thirdparty_files"
}
install_dependencies "$@"
# Pop caller's shell options (quietly)
{ set -vx; eval "${SHELLOPTS_STACK##*|}"; SHELLOPTS_STACK="${SHELLOPTS_STACK%|*}"; } 2> /dev/null