forked from uchicago-dsi/textbook-datascience-1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup-install
executable file
·173 lines (132 loc) · 3.83 KB
/
setup-install
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
#!/usr/bin/env bash
#
# install-cli
#
# Don't like sh/bash/etc? Sure.
#
# Love sh/bash/etc? Yeah, but....
#
# Let's use it here, to bootstrap whatever tools/libraries/etc. we
# *really* love for our project.
#
# Update INSTALL_VERSION to require the version of install-cli this
# script expects
INSTALL_VERSION=0.0.7
#
# start bootstrap installation lib
#
# This is a *bit* of boilerplate to ensure we've downloaded the correct
# version of install-cli. (You probably don't need to touch this.)
#
INSTALL_FILE=.install.${INSTALL_VERSION//./-}.bash.inc
INSTALL_URL=https://raw.githubusercontent.com/dssg/install-cli/$INSTALL_VERSION/install.bash.inc
[ -f $INSTALL_FILE ] || curl -#L $INSTALL_URL -o $INSTALL_FILE
. $INSTALL_FILE
#
# end bootstrap installation lib
#
#
# start project check/install
#
# This is your time to shine!
# Invoke 'require' to ensure your project's basic requirements are met.
#
# Docker
exists_docker() {
icli::check_command docker
}
require docker \
exists_docker
#
# NOTE: This would be well-served by pipenv!
#
# NOTE: However, we want to make sure that contributor can manage environment as
# NOTE: simply and straight-forwardly as possible; and, without built-in, automatic
# NOTE: activation of `pipenv shell`, this would be yet another thing for contributors
# NOTE: to know and do.
#
# NOTE: Therefore, pipenv should definitely be explored for meeting similar requirements
# NOTE: in proper software-development projects. But, here, we'll just try to get
# NOTE: folks up-and-running simply, (and in such a way that doesn't preclude a
# NOTE: proper virtualenv/pyenv environment having already been provisioned).
#
# python
which_python_min() {
# return name of available python command at newest version meeting
# given minimum requirement
#
local min_version="$1"
local installed_info python_exe python_version
for python_version in $(compgen -c python | grep -E "^python[.0-9]+$" | sed 's/^python//' | sort -ut. -k 1,1nr -k2nr); do
python_exe="python$python_version"
installed_info="$($python_exe --version 2> /dev/null)"
if [ $? = 0 ] && [ -z "$installed_info" ]; then
# python <3.4 printed version to stderr
installed_info="$($python_exe --version 2>&1)"
fi
icli::vercomp "${installed_info#* }" $min_version
if [ $? = 2 ]; then
# (continue to next)
:
else
# we have a winner
echo $python_exe
return 0
fi
done
return 1
}
PY_VERSION=3.6
PY_REQUIRED="python${PY_VERSION}+"
PYTHON_EXE=$(which_python_min $PY_VERSION)
PYTHON_OK=$?
PYTHON_FAIL_MESSAGE="please install"
if icli::check_command pyenv; then
PYTHON_FAIL_MESSAGE="${PYTHON_FAIL_MESSAGE}/activate via pyenv"
fi
exists_python() {
return $PYTHON_OK
}
require $PY_REQUIRED \
exists_python \
--fail-prefix="v${PY_VERSION} (or better) not found" \
--fail-with="$PYTHON_FAIL_MESSAGE"
# python libs
PIP_FLAGS=""
if [ -z "$VIRTUAL_ENV" ]; then
PIP_FLAGS="--user"
fi
LIB_VERSION="0.13.1"
lib_installed() {
test "$(pip show argcmdr 2> /dev/null | grep Version | sed 's/Version: //')" == "$LIB_VERSION"
}
install_lib() {
$PYTHON_EXE -m pip install $PIP_FLAGS argcmdr=="$LIB_VERSION"
}
# no great way to check that python libs installed;
# rather, always fail check and let pip figure it out
require lib \
lib_installed \
install_lib \
--fail-message="install libraries (via $PYTHON_EXE)?"
# ensure PATH
manage_on_path() {
icli::check_command manage
}
fix_manage_path() {
local path_prefix
for path_prefix in ".local" "Library/Python/${PYTHON_EXE#python}"; do
if [ -x "$HOME/$path_prefix/bin/manage" ]; then
echo -e "\nexport PATH=\"\$HOME/$path_prefix/bin:\$PATH\"" >> "$HOME/.profile"
return 0
fi
done
return 1
}
require path \
manage_on_path \
fix_manage_path \
--fail-message="modify PATH in ~/.profile file?"
#
# end project check/install
#