forked from mitsuhiko/pipsi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget-pipsi.py
78 lines (57 loc) · 1.83 KB
/
get-pipsi.py
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
#!/usr/bin/env python
import os
import sys
def echo(msg=''):
sys.stdout.write(msg + '\n')
sys.stdout.flush()
def fail(msg):
sys.stderr.write(msg + '\n')
sys.stderr.flush()
sys.exit(1)
def succeed(msg):
echo(msg)
sys.exit(0)
def main():
print('Installing pipsi')
bin_dir = os.path.expanduser('~/.local/bin')
if os.name != 'posix':
fail('So sorry, but pipsi only works on POSIX systems :(')
if os.system('pipsi --version >/dev/null 2>/dev/null') == 0:
succeed('You already have pipsi installed')
if os.system('virtualenv --version >/dev/null 2>/dev/null') != 0:
fail('You need to have virtualenv installed to bootstrap pipsi.')
try:
os.makedirs(bin_dir)
except OSError:
pass
import shutil
from subprocess import Popen
venv = os.path.expanduser('~/.local/venvs/pipsi')
def _cleanup():
try:
shutil.rmdir(venv)
except (OSError, IOError):
pass
if Popen(['virtualenv', venv]).wait() != 0:
_cleanup()
fail('Could not create virtualenv for pipsi :(')
if Popen([venv + '/bin/pip', 'install', 'pipsi']).wait() != 0:
_cleanup()
fail('Could not install pipsi :(')
os.symlink(venv + '/bin/pipsi', bin_dir + '/pipsi')
if os.system('pipsi --version >/dev/null 2>/dev/null') != 0:
echo()
echo('=' * 60)
echo()
echo('Warning:')
echo(' It looks like ~/.local/bin is not on your PATH so pipsi will')
echo(' not work out of the box. To fix this problem make sure to')
echo(' add this to your .bashrc / .profile file:')
echo()
echo(' export PATH=~/.local/bin:$PATH')
echo()
echo('=' * 60)
echo()
succeed('pipsi is now installed.')
if __name__ == '__main__':
main()