-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathpython.sh
More file actions
164 lines (145 loc) · 4.4 KB
/
Copy pathpython.sh
File metadata and controls
164 lines (145 loc) · 4.4 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
# -*- mode: bash; tab-width: 2; -*-
# vim: ts=2 sw=2 ft=bash noet
# Copy the code into the live directory which will be used to run the app
publish_release() {
nos_print_bullet "Moving build into live app directory..."
rsync -a $(nos_code_dir)/ $(nos_app_dir)
}
# Determine the python runtime to install. This will first check
# within the boxfile.yml, then will rely on default_runtime to
# provide a sensible default
runtime() {
echo $(nos_validate \
"$(nos_payload "config_runtime")" \
"string" "$(default_runtime)")
}
# Provide a default python version.
default_runtime() {
echo "python-2.7"
}
# The pip package will look something like py27-pip so
# we need to fetch the condensed runtime to use for the package
condensed_runtime() {
version=$(runtime)
echo "${version//[.thon-]/}"
}
# Install the python runtime along with any dependencies.
install_runtime_packages() {
pkgs=("$(runtime)" "$(condensed_runtime)-setuptools" "$(condensed_runtime)-pip")
# readline and sqlite are needed for most projects
pkgs+=("$(condensed_runtime)-readline" "$(condensed_runtime)-sqlite3")
# add any client dependencies
pkgs+=("$(query_dependencies)")
nos_install ${pkgs[@]}
}
# Uninstall build dependencies
uninstall_build_packages() {
pkgs=("$(condensed_runtime)-pip")
# if pkgs isn't empty, let's uninstall what we don't need
if [[ ${#pkgs[@]} -gt 0 ]]; then
nos_uninstall ${pkgs[@]}
fi
}
# compiles a list of dependencies that will need to be installed
query_dependencies() {
deps=()
# mssql
if [[ `grep -i 'pymssql' $(nos_code_dir)/requirements.txt` ]]; then
deps+=(freetds)
fi
# mysql
if [[ `grep -i 'MySQLdb\|mysqlclient\|MySQL-python' $(nos_code_dir)/requirements.txt` ]]; then
deps+=(mysql-client)
fi
# memcache
if [[ `grep -i 'memcache\|libmc' $(nos_code_dir)/requirements.txt` ]]; then
deps+=(libmemcached)
fi
# postgres
if [[ `grep -i 'psycopg2' $(nos_code_dir)/requirements.txt` ]]; then
deps+=(postgresql94-client)
fi
# redis
if [[ `grep -i 'redis' $(nos_code_dir)/requirements.txt` ]]; then
deps+=(redis)
fi
# curl
if [[ `grep -i 'pycurl' $(nos_code_dir)/requirements.txt` ]]; then
deps+=(curl)
fi
# pillow
if [[ `grep -i 'pillow' $(nos_code_dir)/requirements.txt` ]]; then
deps+=(libjpeg-turbo tiff zlib freetype2 lcms2 libwebp tcl tk)
fi
# boto3
if [[ `grep -i 'boto3' $(nos_code_dir)/requirements.txt` ]]; then
deps+=("$(condensed_runtime)-cElementTree")
fi
# xmlsec
if [[ `grep -i 'xmlsec' $(nos_code_dir)/requirements.txt` ]]; then
deps+=(libxml2 libxslt xmlsec1 pkgconf)
fi
# python3-saml
if [[ `grep -i 'python3-saml' $(nos_code_dir)/requirements.txt` ]]; then
deps+=(libxml2 libxslt xmlsec1 pkgconf)
fi
# pygraphviz
if [[ `grep -i 'pygraphviz' $(nos_code_dir)/requirements.txt` ]]; then
deps+=(libxshmfence libva libvdpau libLLVM-3.8 graphviz)
fi
# scipy
if [[ `grep -i 'scipy' $(nos_code_dir)/requirements.txt` ]]; then
deps+=(blas lapack)
fi
echo "${deps[@]}"
}
# set any necessary python environment variables
setup_python_env() {
# ensure python doesn't buffer even when not attached to a pty
nos_template_file \
"env.d/PYTHONUNBUFFERED" \
"$(nos_etc_dir)/env.d/PYTHONUNBUFFERED"
}
# fetch the user-specified pip install command or use a default
pip_install_cmd() {
echo $(nos_validate \
"$(nos_payload "config_pip_install")" \
"string" "$(default_pip_install)")
}
# the default pip install cmd when a user-specified cmd is not present
default_pip_install() {
echo "\
pip install \
-I \
-r requirements.txt \
--disable-pip-version-check \
--no-cache-dir \
--target=$(nos_code_dir)/.nanobox/pip/src \
--upgrade \
--install-option='--install-scripts=$(nos_code_dir)/.nanobox/pip/bin'"
}
# Install dependencies via pip from requirements.txt
pip_install() {
if [[ -f $(nos_code_dir)/requirements.txt ]]; then
cd $(nos_code_dir)
nos_run_process "Running pip install" \
"$(pip_install_cmd)"
cd - >/dev/null
fi
}
# Generate the payload to render the pip env profile.d template
pip_env_payload() {
cat <<-END
{
"code_dir": "$(nos_code_dir)"
}
END
}
# Since we install pip modules into a custom cache_dir, we need
# to setup the environment (with env vars) for the python app to work
set_pip_env() {
nos_template \
"profile.d/pip.sh" \
"$(nos_etc_dir)/profile.d/pip.sh" \
"$(pip_env_payload)"
}