-
Notifications
You must be signed in to change notification settings - Fork 0
/
bootstrap.py
executable file
·62 lines (44 loc) · 1.58 KB
/
bootstrap.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
#!/usr/bin/env python
import os
import subprocess
import sys
if sys.version_info < (3, 5):
print('Only Python 3.5 and later are supported.')
sys.exit(1)
DIR = os.path.dirname(__file__) or '.'
PLATFORM = ''.join(c for c in sys.platform if c.isalpha())
VIRTUALENVDIR = os.path.join('venv', '%s-%d.%d' % (
PLATFORM, sys.version_info.major, sys.version_info.minor))
def rel(path):
return os.path.join(DIR, path)
COMMANDS = {
'darwin': [rel('scripts/bootstrap/main.sh')],
'linux': [rel('scripts/bootstrap/main.sh')],
'win': ['cmd', '/C', rel('scripts\\bootstrap\\main.bat')]}[PLATFORM]
ACTIVATOR = {
'darwin': '. %s/bin/activate' % VIRTUALENVDIR,
'linux': '. %s/bin/activate' % VIRTUALENVDIR,
'win': 'call %s\\Scripts\\activate.bat' % VIRTUALENVDIR}[PLATFORM]
try:
subprocess.check_call(
COMMANDS + [VIRTUALENVDIR, sys.executable],
cwd=DIR)
print('''
Successfully bootstrapped! Run this command to activate the virtualenv:
%s
''' % ACTIVATOR)
except subprocess.CalledProcessError as e:
sys.exit(e.returncode)
def zip_to_dir(path):
"""Converts a zipped egg to an unzipped directory with the same name.
A backup will be saved as ``'%s.zip' % path``.
:param str path: The path to the egg.
"""
print('Unzipping %s...' % path)
zpath = '%s.zip' % path
os.rename(path, zpath)
subprocess.check_call(['python', '-m', 'zipfile', '-e', zpath, path])
# Unzip all zipped eggs
for root, dirs, files in os.walk(DIR):
for name in (f for f in files if f.endswith('.egg')):
zip_to_dir(os.path.join(root, name))