forked from cloudfoundry/python-buildpack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconda-install
More file actions
executable file
·91 lines (77 loc) · 2.98 KB
/
conda-install
File metadata and controls
executable file
·91 lines (77 loc) · 2.98 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
#!/usr/bin/env bash
# Cloud Foundry Python Conda Buildpack
# Copyright (c) 2014-2015 the original author or authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
echo "-----> Starting compile step..."
BUILD_DIR=$1
CACHE=$2
BASH=$(which bash)
WGET=$(which wget)
CONDA_HOME="$1/.conda"
CONDA_BIN="$CONDA_HOME/bin"
CONDA_ENVS="$CONDA_HOME/envs"
CONDA_ENVS_CACHE="$CACHE/envs"
RUNTIME="$BUILD_DIR/runtime.txt"
# Get the runtime version and download appropriate Miniconda
MINICONDA_VERSION="4.2.12"
if [ -e $RUNTIME ]; then
PYTHON_VERSION=$(cut -d- -f2 $RUNTIME)
if [ ${PYTHON_VERSION:0:1} -eq 3 ]; then
PYTHON_MAJOR_VERSION=3
elif [ ${PYTHON_VERSION:0:1} -eq 2 ]; then
PYTHON_MAJOR_VERSION=2
else
PYTHON_MAJOR_VERSION=""
fi
MINICONDA_FILE="Miniconda${PYTHON_MAJOR_VERSION}-${MINICONDA_VERSION}-Linux-x86_64.sh"
else
MINICONDA_FILE="Miniconda2-${MINICONDA_VERSION}-Linux-x86_64.sh"
fi
MINICONDA_URI="http://repo.continuum.io/miniconda/$MINICONDA_FILE"
MINICONDA_CACHE="$CACHE/$MINICONDA_FILE"
PROFILE_PATH="$BUILD_DIR/.profile.d/conda.sh"
echo "-----> Preparing Python Environment..."
if [ ! -e $MINICONDA_CACHE ] ; then
echo "-----> Downloading Miniconda..."
if [ ! -d $CACHE ]; then mkdir $CACHE; fi
$WGET -q -O $MINICONDA_CACHE $MINICONDA_URI
chmod +x $MINICONDA_CACHE
fi
if [ -e $CONDA_HOME ]; then rm -rf $CONDA_HOME; fi
# Install miniconda
$MINICONDA_CACHE -b -p $CONDA_HOME #&> /dev/null
if [ -e $CONDA_ENVS_CACHE ] ; then
echo "-----> Using dependency cache at $CONDA_ENVS_CACHE"
cp -R $CONDA_ENVS_CACHE/* $CONDA_ENVS
else
mkdir -p $CONDA_ENVS_CACHE
fi
CONDA_ENV="dep_env"
echo "-----> Installing Dependencies..."
echo "-----> Installing conda environment from environment.yml..."
$CONDA_BIN/conda env update --quiet -n $CONDA_ENV -f "$BUILD_DIR/environment.yml"
$CONDA_BIN/conda clean -pt
echo "-----> Caching dependencies to $CONDA_ENVS_CACHE"
cp -R $CONDA_ENVS/* $CONDA_ENVS_CACHE
echo "-----> Fixing paths..."
grep -rlI $BUILD_DIR $BUILD_DIR | xargs sed -i.bak "s|$BUILD_DIR|/home/vcap/app|g"
# Add Conda path to profile
mkdir -p $(dirname $PROFILE_PATH)
echo "export PATH=$HOME/app/.conda/bin:\$PATH" >> $PROFILE_PATH
echo "source activate $CONDA_ENV" >> $PROFILE_PATH
if test -f $BUILD_DIR/runtime.txt && grep 'python=' $BUILD_DIR/environment.yml; then
echo "WARNING: you have specified the version of Python runtime both in 'runtime.txt' and 'environment.yml'. You should remove one of the two versions"
fi
echo "-----> Finished compile step"