-
Notifications
You must be signed in to change notification settings - Fork 9.6k
/
Copy pathutils.sh
41 lines (35 loc) · 954 Bytes
/
utils.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
#!/usr/bin/env bash
# This script contains utility functions and initialize exmaple scripts.
# Eg: run_python_examples.sh, run_distributed_examples.sh
BASE_DIR="$(pwd)/$(dirname $0)"
EXAMPLES=$(echo $1 | sed -e 's/ //g')
# Redirect 'python' calls to 'python3'
python() {
command python3 "$@"
}
ERRORS=${ERRORS-""}
function error() {
ERR=$1
if [ "" == "$ERRORS" ]; then
ERRORS="$ERR"
else
ERRORS="$ERRORS\n$ERR"
fi
}
function install_deps() {
EXAMPLE_NAME=$1
echo "] $EXAMPLE_NAME: installing requirements"
[[ -f requirements.txt ]] || return
for req in $(cat requirements.txt); do
# testing the installed version of torch, so don't pip install it.
if [[ "$req" != "torch" ]]; then
pip install "$req" || { error "failed to install $req"; exit 1; }
fi
done
}
function start() {
EXAMPLE_NAME=${FUNCNAME[1]}
cd $BASE_DIR/$EXAMPLE_NAME
install_deps $EXAMPLE_NAME
echo "] $EXAMPLE_NAME: running"
}