forked from cloudfoundry/python-buildpack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpython
More file actions
executable file
·104 lines (83 loc) · 3.35 KB
/
python
File metadata and controls
executable file
·104 lines (83 loc) · 3.35 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
source $BIN_DIR/utils
PYTHON_VERSION=''
if [ -f runtime.txt ]; then
PYTHON_VERSION=$(cat runtime.txt)
fi
PYTHON_VERSION=$($BUILDPACK_PATH/bin/steps/libs/version.rb $BUILDPACK_PATH/manifest.yml $PYTHON_VERSION)
PYTHON_DIR=$DEPS_DIR/$DEPS_IDX/python
# Install Python.
if [ -f $CACHE_DIR/python-stack ]; then
if [ ! $(cat $CACHE_DIR/python-stack) = $CF_STACK ]; then
rm -fr $PYTHON_DIR $CACHE_DIR/python-version $CACHE_DIR/python-stack $CACHE_DIR/vendor
unset SKIP_INSTALL
fi
fi
if [ -f $CACHE_DIR/python-version ]; then
if [ ! $(cat $CACHE_DIR/python-version) = $PYTHON_VERSION ]; then
puts-step "Found $(cat $CACHE_DIR/python-version), removing"
rm -fr $PYTHON_DIR $CACHE_DIR/python-version $CACHE_DIR/python-stack $CACHE_DIR/vendor
else
SKIP_INSTALL=1
fi
fi
if [ -z "${SKIP_INSTALL:-}" ]; then
puts-step "Installing $PYTHON_VERSION"
# Prepare destination directory.
mkdir $PYTHON_DIR
exit_code=0
SHORT_PYTHON_VERSION=$(echo $PYTHON_VERSION | sed "s|python-||")
filtered_url=$($BUILDPACK_PATH/compile-extensions/bin/download_dependency_by_name python $SHORT_PYTHON_VERSION /tmp/python.tar.gz) || exit_code=$?
if [ $exit_code -ne 0 ]; then
$BUILDPACK_PATH/compile-extensions/bin/recommend_dependency_by_name python $SHORT_PYTHON_VERSION
exit 1
fi
$BUILDPACK_PATH/compile-extensions/bin/warn_if_newer_patch_by_name python $SHORT_PYTHON_VERSION
tar zxvf /tmp/python.tar.gz -C $PYTHON_DIR &> /dev/null
echo "Downloaded [$filtered_url]"
FRESH_PYTHON=true
fi
# Link
pushd $DEPS_DIR/$DEPS_IDX/bin >/dev/null
ln -s ../python/bin/* .
popd >/dev/null
pushd $DEPS_DIR/$DEPS_IDX/lib >/dev/null
ln -s ../python/lib/* .
popd >/dev/null
# Record for future reference.
echo $PYTHON_VERSION > "$CACHE_DIR/python-version"
echo $CF_STACK > "$CACHE_DIR/python-stack"
hash -r
PIP_VERSION=$($BUILDPACK_PATH/compile-extensions/bin/default_version_for $BUILDPACK_PATH/manifest.yml pip)
SETUPTOOLS_VERSION=$($BUILDPACK_PATH/compile-extensions/bin/default_version_for $BUILDPACK_PATH/manifest.yml setuptools)
# If Pip isn't up to date:
if [ -n "${FRESH_PYTHON:-}" ] || [[ ! $(pip --version) == *$PIP_VERSION* ]]; then
TMPTARDIR=$(mktemp -d)
# Prepare it for the real world
puts-step "Installing Setuptools ($SETUPTOOLS_VERSION)"
filtered_url=$($BUILDPACK_PATH/compile-extensions/bin/download_dependency_by_name setuptools $SETUPTOOLS_VERSION /tmp/setuptools.tgz)
echo "Downloaded [$filtered_url]"
tar zxf /tmp/setuptools.tgz -C $TMPTARDIR
pushd $TMPTARDIR/setuptools-$SETUPTOOLS_VERSION/ >/dev/null
python setup.py install --prefix=$DEPS_DIR/$DEPS_IDX/python &> /dev/null
popd >/dev/null
puts-step "Installing Pip ($PIP_VERSION)"
filtered_url=$($BUILDPACK_PATH/compile-extensions/bin/download_dependency_by_name pip $PIP_VERSION /tmp/pip.tgz)
echo "Downloaded [$filtered_url]"
tar zxf /tmp/pip.tgz -C $TMPTARDIR
pushd $TMPTARDIR/pip-$PIP_VERSION/ >/dev/null
python setup.py install --prefix=$DEPS_DIR/$DEPS_IDX/python &> /dev/null
popd >/dev/null
pushd $DEPS_DIR/$DEPS_IDX/bin >/dev/null
ln -sf ../python/bin/* .
popd >/dev/null
pushd $DEPS_DIR/$DEPS_IDX/lib >/dev/null
ln -sf ../python/lib/* .
popd >/dev/null
fi
pushd $DEPS_DIR/$DEPS_IDX/include >/dev/null
ln -sf ../python/include/* .
popd >/dev/null
pushd $DEPS_DIR/$DEPS_IDX/pkgconfig >/dev/null
ln -sf ../python/lib/pkgconfig/* .
popd >/dev/null
hash -r