Skip to content

Commit e45a973

Browse files
author
Joe Jevnik
committed
DEV: add conda_build_matrix.py to help upload packages
1 parent 88e4758 commit e45a973

File tree

2 files changed

+108
-6
lines changed

2 files changed

+108
-6
lines changed

docs/source/release-process.rst

+22
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,28 @@ Once we are happy, push the updated docs to the GitHub ``gh-pages`` branch.
169169
170170
`zipline.io <http://www.zipline.io/index.html>`__ will update in a few moments.
171171

172+
Uploading conda packages
173+
~~~~~~~~~~~~~~~~~~~~~~~~
174+
175+
To build the conda packages for zipline run:
176+
177+
.. code-block:: bash
178+
179+
$ python etc/conda_build_matrix.py
180+
181+
If all of the builds succeed, then this will not print anything and exit with
182+
``EXIT_SUCCESS``. If there are build issues, we must address them and decide
183+
what to do.
184+
185+
Once all of the builds in the matrix pass, we can upload them to anaconda with:
186+
187+
.. code-block:: bash
188+
189+
$ python etc/conda_build_matrix.py --upload
190+
191+
If you would like to test this command by uploading to a different user, this
192+
may be specified with the ``--user`` flag.
193+
172194
Next Commit
173195
~~~~~~~~~~~
174196

etc/conda_build_matrix.py

+86-6
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,95 @@
11
from itertools import product
22
import os
3+
import subprocess
4+
5+
import click
36

47
py_versions = ('2.7', '3.4')
5-
numpy_versions = ('1.9', '1.10')
8+
npy_versions = ('1.9', '1.10')
9+
zipline_path = os.path.join(
10+
os.path.dirname(__file__),
11+
'..',
12+
'conda',
13+
'zipline',
14+
)
15+
16+
17+
def mkargs(py_version, npy_version, output=False):
18+
return {
19+
'args': [
20+
'conda',
21+
'build',
22+
zipline_path,
23+
'-c', 'quantopian',
24+
'--python=%s' % py_version,
25+
'--numpy=%s' % npy_version,
26+
] + (['--output'] if output else []),
27+
'stdout': subprocess.PIPE,
28+
'stderr': subprocess.PIPE,
29+
}
30+
631

32+
@click.command()
33+
@click.option(
34+
'--upload',
35+
is_flag=True,
36+
default=False,
37+
help='Upload packages after building',
38+
)
39+
@click.option(
40+
'--upload-only',
41+
is_flag=True,
42+
default=False,
43+
help='Upload the last built packages without rebuilding.',
44+
)
45+
@click.option(
46+
'--user',
47+
default='quantopian',
48+
help='The anaconda account to upload to.',
49+
)
50+
def main(upload, upload_only, user):
51+
if upload_only:
52+
# if you are only uploading you shouldn't need to specify both flags
53+
upload = True
54+
procs = (
55+
(
56+
py_version,
57+
npy_version,
58+
(subprocess.Popen(**mkargs(py_version, npy_version))
59+
if not upload_only else
60+
None),
61+
)
62+
for py_version, npy_version in product(py_versions, npy_versions)
63+
)
64+
status = 0
65+
files = []
66+
for py_version, npy_version, proc in procs:
67+
if not upload_only:
68+
out, err = proc.communicate()
69+
if proc.returncode:
70+
status = 1
71+
print('build failure: python=%s numpy=%s\n%s' % (
72+
py_version,
73+
npy_version,
74+
err.decode('utf-8'),
75+
))
76+
elif upload:
77+
files.append(subprocess.Popen(
78+
**mkargs(py_version, npy_version, output=True)
79+
).communicate()[0].decode('utf-8').strip())
780

8-
def main():
9-
for pair in product(py_versions, numpy_versions):
10-
os.system('conda build conda/zipline -c quantopian '
11-
'--python=%s --numpy=%s' % pair)
81+
if not status and upload:
82+
for f in files:
83+
p = subprocess.Popen(
84+
['anaconda', 'upload', '-u', user, f],
85+
stdout=subprocess.DEVNULL,
86+
stderr=subprocess.DEVNULL,
87+
)
88+
out, err = p.communicate()
89+
if p.returncode:
90+
print('failed to upload: %s\n%s' % (f, err.decode('utf-8')))
91+
return status
1292

1393

1494
if __name__ == '__main__':
15-
main()
95+
exit(main())

0 commit comments

Comments
 (0)