-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstartenv
More file actions
executable file
·107 lines (86 loc) · 2.82 KB
/
Copy pathstartenv
File metadata and controls
executable file
·107 lines (86 loc) · 2.82 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
#!/bin/bash
PYTHON_VERSION=3.6.1
ROOT_DIR=`pwd`
LOCAL_PYTHON=${ROOT_DIR}/.localpython
VIRTUALENV_DIR='python_env'
PYTHON_BIN=python
if [[ ${PYTHON_VERSION:0:1} == '3' ]]; then
PYTHON_BIN=python3
fi
# Install a package if it's not present
# Usage: install_package binary [package]
# Checks if "which binary" is successful, if not, installs the package
# If package isn't given, defaults to the same name as binary
function install_package {
BINARY=$1
PACKAGE=${2:-$BINARY}
if [ -z "$(which $BINARY 2>/dev/null)" ]
then
case "$PACKAGE" in
pip)
curl -fsSL https://bootstrap.pypa.io/get-pip.py > get-pip.py
sudo python get-pip.py
rm get-pip.py
;;
brew)
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
export PATH=$PATH:/usr/local/bin
;;
*)
if [ "$(uname -s)" = "Darwin" ]
then
brew install $PACKAGE
else
found=$(dpkg -l $PACKAGE | grep -qv "no packages found matching" || echo 1)
if [ ! $found = "" ]; then
echo "Installing $PACKAGE"
sudo apt-get -y -qq install $PACKAGE
fi
fi
;;
esac
fi
}
function install_python(){
if [ ! -f ${LOCAL_PYTHON}/bin/${PYTHON_BIN} ]; then
if [ ! -d ${ROOT_DIR}/.src ]; then
mkdir ${ROOT_DIR}/.src
fi
cd ${ROOT_DIR}/.src
PYTHON_TAR=Python-${PYTHON_VERSION}.tgz
if [ ! -f $PYTHON_TAR ]; then
wget http://www.python.org/ftp/python/${PYTHON_VERSION}/$PYTHON_TAR
fi
if [ ! -d Python-${PYTHON_VERSION} ]; then
tar -zxvf $PYTHON_TAR
fi
cd Python-${PYTHON_VERSION}
if [ ! -d $LOCAL_PYTHON ]; then
mkdir $LOCAL_PYTHON
fi
# Install SQLite
PACKAGES=( libsqlite3-dev libreadline6 libreadline6-dev libbz2-dev libdbm-ocaml-dev libgdbm-dev libcurses-ocaml-dev )
for package in ${PACKAGES[@]}
do
install_package $package
done
./configure --prefix=$LOCAL_PYTHON
make
make install
cd $ROOT_DIR
fi
}
#==============================================================================
if [ -z $VIRTUAL_ENV ]; then
if [ ! -f "${ROOT_DIR}/python_env/bin/activate" ]; then
install_python
echo "Creating virtual environment."
${LOCAL_PYTHON}/bin/${PYTHON_BIN} -m venv $VIRTUALENV_DIR
fi
. ./python_env/bin/activate
pip install --upgrade virtualenv pip
./refreshenv
export PATH=$PATH:`npm bin`
else
echo "Already in a virtualenv. Not doing anything!"
fi