forked from scrtlabs/catalyst
-
Notifications
You must be signed in to change notification settings - Fork 0
/
conda_build_matrix.py
118 lines (108 loc) · 3.22 KB
/
conda_build_matrix.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
from itertools import product
import os
import subprocess
import click
py_versions = ('2.7', '3.4', '3.5')
npy_versions = ('1.9', '1.10')
catalyst_path = os.path.join(
os.path.dirname(__file__),
'..',
'conda',
'catalyst',
)
def mkargs(py_version, npy_version, output=False):
return {
'args': [
'conda',
'build',
catalyst_path,
'-c', 'quantopian',
'--python=%s' % py_version,
'--numpy=%s' % npy_version,
] + (['--output'] if output else []),
'stdout': subprocess.PIPE,
'stderr': subprocess.PIPE,
}
@click.command()
@click.option(
'--upload',
is_flag=True,
default=False,
help='Upload packages after building',
)
@click.option(
'--upload-only',
is_flag=True,
default=False,
help='Upload the last built packages without rebuilding.',
)
@click.option(
'--allow-partial-uploads',
is_flag=True,
default=False,
help='Upload any packages that were built even if some of the builds'
' failed.',
)
@click.option(
'--user',
default='quantopian',
help='The anaconda account to upload to.',
)
def main(upload, upload_only, allow_partial_uploads, user):
if upload_only:
# if you are only uploading you shouldn't need to specify both flags
upload = True
procs = (
(
py_version,
npy_version,
(subprocess.Popen(**mkargs(py_version, npy_version))
if not upload_only else
None),
)
for py_version, npy_version in product(py_versions, npy_versions)
)
status = 0
files = []
for py_version, npy_version, proc in procs:
if not upload_only:
out, err = proc.communicate()
if proc.returncode:
status = 1
print('build failure: python=%s numpy=%s\n%s' % (
py_version,
npy_version,
err.decode('utf-8'),
))
# don't add the filename to the upload list if the build
# fails
continue
if upload:
p = subprocess.Popen(
**mkargs(py_version, npy_version, output=True)
)
out, err = p.communicate()
if p.returncode:
status = 1
print(
'failed to get the output name for python=%s numpy=%s\n'
'%s' % (py_version, npy_version, err.decode('utf-8')),
)
else:
files.append(out.decode('utf-8').strip())
if (not status or allow_partial_uploads) and upload:
for f in files:
p = subprocess.Popen(
['anaconda', 'upload', '-u', user, f],
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL,
)
out, err = p.communicate()
if p.returncode:
# only change the status to failure if we are not allowing
# partial uploads
status |= not allow_partial_uploads
print('failed to upload: %s\n%s' % (f, err.decode('utf-8')))
return status
if __name__ == '__main__':
exit(main())