forked from mozilla/ichnaea
-
Notifications
You must be signed in to change notification settings - Fork 0
/
compile_wheels.py
76 lines (59 loc) · 2.48 KB
/
compile_wheels.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
"""
This script is used as part of the "make wheel" command, used as part
of the travis-ci setup to create a cached wheelhouse which survives
consecutive builds and speeds up the build process.
It creates local wheels for all the Python dependencies containing
C extensions. Unfortunately "bin/pip wheel" doesn't recognize that
it already has a local wheel for these dependencies and would build
them again, so we manually check the presence of the wheel files.
This only works with requirement files containing exact version pins.
"""
from glob import glob
from optparse import OptionParser
import os
import os.path
import sys
from pip.req import parse_requirements
def absolute_path(path):
return os.path.abspath(os.path.expanduser(path))
def build_wheels(command, wheelhouse, files):
print command, wheelhouse, files
if not os.path.isdir(wheelhouse):
print('Wheelhouse %s not found.' % wheelhouse)
return 0
for filename in files:
if not os.path.isfile(filename):
print('Requirements file not found: %s' % filename)
return 1
for req in list(parse_requirements(filename, session=object())):
reqname = req.name
specs = req.req.specs
if len(specs) != 1:
print('Skipping wheel, multiple requirements for %s' % reqname)
op, version = specs[0]
if op != '==':
print('Skipping wheel, non-exact requirement for %s' % reqname)
pattern = os.path.join(wheelhouse,
'%s-%s-*.whl' % (reqname, version))
found = glob(pattern)
if found:
print ('Skipping build, wheel already exists: %s' % found)
continue
os.system('%s %s==%s' % (command, reqname, version))
return 0
def main():
parser = OptionParser()
parser.add_option('-c', '--command', dest='command')
parser.add_option('-w', '--wheelhouse', dest='wheelhouse')
parser.add_option('-f', '--file', dest='files',
action='append', default=[])
(options, _) = parser.parse_args()
if not options.command or not options.wheelhouse or not options.files:
parser.error('options -c, -w and -f are required')
command = options.command
wheelhouse = absolute_path(options.wheelhouse)
files = [absolute_path(f) for f in options.files]
status = build_wheels(command, wheelhouse, files)
sys.exit(status)
if __name__ == '__main__':
main()