-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathlinuxdeploy-plugin-conda.sh
executable file
·172 lines (139 loc) · 4.23 KB
/
linuxdeploy-plugin-conda.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
#! /bin/bash
# abort on all errors
set -e
if [ "$DEBUG" != "" ]; then
set -x
fi
script=$(readlink -f "$0")
show_usage() {
echo "Usage: $script --appdir <path to AppDir>"
echo
echo "Bundles software available as conda packages into an AppDir"
echo
echo "Variables:"
echo " CONDA_CHANNELS=\"channelA;channelB;...\""
echo " CONDA_PACKAGES=\"packageA;packageB;...\""
echo " CONDA_PYTHON_VERSION=\"3.6\""
echo " PIP_REQUIREMENTS=\"packageA packageB -r requirements.txt -e git+https://...\""
echo " PIP_PREFIX=\"AppDir/usr/share/conda\""
echo " BLOAT_REMOVE_SKIP=\"setuptools;pip\""
}
APPDIR=
while [ "$1" != "" ]; do
case "$1" in
--plugin-api-version)
echo "0"
exit 0
;;
--appdir)
APPDIR="$2"
shift
shift
;;
--help)
show_usage
exit 0
;;
*)
echo "Invalid argument: $1"
echo
show_usage
exit 1
;;
esac
done
if [ "$APPDIR" == "" ]; then
show_usage
exit 1
fi
mkdir -p "$APPDIR"
if [ "$CONDA_PACKAGES" == "" ]; then
echo "WARNING: \$CONDA_PACKAGES not set, no packages will be installed!"
fi
# create temporary directory into which downloaded files are put
TMPDIR=$(mktemp -d)
_cleanup() {
rm -rf "$TMPDIR"
}
trap _cleanup EXIT
if [ -d "$APPDIR"/usr/conda ]; then
echo "Error: directory exists: $APPDIR/usr/conda"
exit 1
fi
# install Miniconda, a self contained Python distribution, into AppDir
(cd "$TMPDIR" && wget https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh)
# install into usr/conda/ instead of usr/ to make sure that the libraries shipped with conda don't overwrite or
# interfere with libraries bundled by other plugins or linuxdeploy itself
bash "$TMPDIR"/Miniconda3-latest-Linux-x86_64.sh -b -p "$APPDIR"/usr/conda -f
# activate environment
. "$APPDIR"/usr/conda/bin/activate
# we don't want to touch the system, therefore using a temporary home
mkdir _temp_home
export HOME=$(readlink -f _temp_home)
# conda-forge is used by many conda packages, therefore we'll add that channel by default
conda config --add channels conda-forge
# force-install libxi, required by a majority of packages on some more annoying distributions like e.g., Arch
#conda install -y xorg-libxi
# force another python version if requested
if [ "$CONDA_PYTHON_VERSION" != "" ]; then
conda install -y python="$CONDA_PYTHON_VERSION"
fi
# add channels specified via $CONDA_CHANNELS
IFS=';' read -ra chans <<< "$CONDA_CHANNELS"
for chan in "${chans[@]}"; do
conda config --append channels "$chan"
done
# install packages specified via $CONDA_PACKAGES
IFS=';' read -ra pkgs <<< "$CONDA_PACKAGES"
for pkg in "${pkgs[@]}"; do
conda install -y "$pkg"
done
# install requirements from PyPI specified via $PIP_REQUIREMENTS
if [ "$PIP_REQUIREMENTS" != "" ]; then
if [ "$PIP_WORKDIR" != "" ]; then
pushd "$PIP_WORKDIR"
fi
pip install -U $PIP_REQUIREMENTS ${PIP_PREFIX:+--prefix=$PIP_PREFIX} ${PIP_VERBOSE:+-v}
if [ "$PIP_WORKDIR" != "" ]; then
popd
fi
fi
# create symlinks for all binaries in usr/conda/bin/ in usr/bin/
mkdir -p "$APPDIR"/usr/bin/
for i in "$APPDIR"/usr/conda/bin/*; do
ln -s -r "$i" "$APPDIR"/usr/bin/
done
# get whitelist of bloat to not remove for this package
IFS=';' read -ra bloatskip <<< "$BLOAT_REMOVE_SKIP"
# remove bloat
pushd "$APPDIR"/usr/conda
rm -rf pkgs
find -type d -iname '__pycache__' -print0 | xargs -0 rm -r
find -type f -iname '*.so*' -print -exec strip '{}' \;
find -type f -iname '*.a' -print -delete
rm -rf lib/cmake/
rm -rf include/
rm -rf share/{gtk-,}doc
rm -rf share/man
# remove setuptools unless whitelisted
for entry in "${bloatskip[@]}"; do
if [ "$entry" == "setuptools" ]; then
break
fi
rm -rf lib/python?.?/site-packages/setuptools
done
# remove pip unless whitelisted
for entry in "${bloatskip[@]}"; do
if [ "$entry" == "pip" ]; then
break
fi
rm -rf lib/python?.?/site-packages/pip
done
# remove distutils unless whitelisted
for entry in "${bloatskip[@]}"; do
if [ "$entry" == "distutils" ]; then
break
fi
rm -rf lib/python?.?/distutils
done
popd