This repository has been archived by the owner on Jan 4, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsandbox.sh
54 lines (48 loc) · 1.9 KB
/
sandbox.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
if [[ -z "`which pip3 2> /dev/null`" ]]; then
echo "pip3 must be installed"
echo "Aborting..."
return
fi
# Set up a virtualenv if it doesn't already exist
if [[ ! -d $PWD/.venv ]]; then
curl --silent --retry 3 --retry-delay 1 --head http://google.com > /dev/null
if [[ "$?" -ne 0 ]]; then
echo "No internet connection available"
echo "Aborting..."
return
fi
if [[ -z "`which virtualenv 2> /dev/null`" ]]; then
while true; do
read -p "You do not have virtualenv installed. Should I install it using pip? [Y/N]" yn
case $yn in
[Yy]* )
if [[ -z "`which sudo 2> /dev/null`" ]]; then
pip3 install virtualenv;
else
sudo pip3 install virtualenv;
fi
if [[ -z "`which virtualenv 2> /dev/null`" ]]; then
echo 'Failed to install virtualenv'
return
fi
break;;
[Nn]* ) echo "Please install virtualenv"; return;;
* ) echo "Answer yes or no";;
esac
done
fi
virtualenv -p python3 --no-site-packages $PWD/.venv
$PWD/.venv/bin/pip install -U pip
$PWD/.venv/bin/pip install -r $PWD/requirements.txt
if [[ ! -d $PWD/tests ]]; then
$PWD/.venv/bin/python $PWD/robot.py add-tests 2> /dev/null
fi
ln -sf $PWD/hooks/* $PWD/.git/hooks/
fi
export PATH=$PWD/.venv/bin:$PATH
# Upgrade any out-of-date pip packages
# HACK: It would be better to include the logic for updating pip packages right
# here, but direnv waits for all subshells and functions to finish before it
# initializes the environment, which causes a noticeable hang when cd-ing into
# the repository. Running a script in the background does not cause a delay.
(bash $PWD/hooks/post-merge envrc &)