forked from HubSpot/pv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pv
executable file
·67 lines (48 loc) · 1.53 KB
/
pv
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
#!/bin/bash
set -e
BASE_DIR="$HOME/.pv"
VIRTUALENV_DIR="$BASE_DIR/virtualenvs"
BIN_DIR="$BASE_DIR/bin"
PACKAGE=$1
if [ $# -lt 1 ]; then
echo "pv -- pip install directly into a virtualenv"
echo "Example: pv httpie==0.5.0"
exit 1
fi
PACKAGE_NAME=($(echo $PACKAGE | tr "=<>" " "))
[ -d $VIRTUALENV_DIR ] || mkdir -p $VIRTUALENV_DIR
[ -d $BIN_DIR ] || mkdir -p $BIN_DIR
if [ ! -e "$VIRTUALENV_DIR/$PACKAGE_NAME/bin/activate" ]; then
echo "----> creating virtualenv $PACKAGE_NAME"
virtualenv "$VIRTUALENV_DIR/$PACKAGE_NAME"
fi
. $VIRTUALENV_DIR/$PACKAGE_NAME/bin/activate
echo "----> installing / upgrading $PACKAGE"
pip install -U $PACKAGE
echo "----> collecting executables"
[ -d "$BIN_DIR/$PACKAGE_NAME" ] && rm -r $BIN_DIR/$PACKAGE_NAME
mkdir $BIN_DIR/$PACKAGE_NAME
for f in $VIRTUALENV_DIR/$PACKAGE_NAME/bin/*; do
[ -x "$f" ] || continue # must be executable
filename=$(basename $f)
[[ $filename =~ ^(easy_install|pip|python)-?\d?\.?\d? ]] && continue
ln -sf $f "$BIN_DIR/$PACKAGE_NAME/$filename"
echo " - $filename"
done
echo "----> complete"
echo ""
# lay down env.sh if it doesnt exist
if [ ! -e "$BASE_DIR/env.sh" ]; then
echo "for f in $BIN_DIR/*; do
[ -d \$f ] || continue
export PATH=\"\$f:\$PATH\"
done
export PV_LOADED=1
" > $BASE_DIR/env.sh
fi
if [ -z $PV_LOADED ]; then
echo "add this line to your .bashrc / .zshrc:"
echo "[ -f \"$BASE_DIR/env.sh\" ] && source \"$BASE_DIR/env.sh\""
else
echo "you may need to restart your shell in order for this to take effect"
fi