-
Notifications
You must be signed in to change notification settings - Fork 1
/
venv-helper
79 lines (66 loc) · 2.28 KB
/
venv-helper
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
#!/usr/bin/env bash
function v(){
case $(echo $1 | tr 'A-Z' 'a-z') in
create)
local psw=''
if [[ "${3:0:3}" = '-p=' ]]; then
local pyv="${3:3}"
local isgood=0
if ! [[ $pyv =~ / ]]; then
if ! [[ -d $HOME/.virtualenv/py/$pyv ]]; then
(
cd $HOME/.virtualenv/cpython
hg up 0 &> /dev/null
rm -r * &> /dev/null
yes c | hg checkout $pyv &> /dev/null
if [ $? -eq 0 ]; then
./configure --prefix $HOME/.virtualenv/py/$pyv &> /dev/null
make &> /dev/null
make install &> /dev/null
hg up 0 &> /dev/null
rm -r * &> /dev/null
else
exit 1
fi
)
if [ $? -eq 0 ]; then
isgood=1
pyv=$HOME/.virtualenv/py/$pyv
fi
else
isgood=1
pyv=$HOME/.virtualenv/py/$pyv
fi
else
isgood=1
fi
if let isgood; then
if [[ -e $pyv/bin/python ]]; then
psw="-p $pyv/bin/python"
else
psw="-p $pyv/bin/python3"
fi
else
echo "Invalid Python version."
return 1
fi
fi
if ! [[ -d "$HOME/.virtualenv/envs/$2" ]]; then
virtualenv $psw "$HOME/.virtualenv/envs/$2"
else
echo "$2 already exists."
fi
;&
use)
source "$HOME/.virtualenv/envs/$2/bin/activate"
;;
#list)
#find
*)
echo 'Usage:'
echo ' v list'
echo ' v use <env>'
echo ' v create <env> [-p=<python>]'
;;
esac
}