|
1 | 1 | from itertools import product
|
2 | 2 | import os
|
| 3 | +import subprocess |
| 4 | + |
| 5 | +import click |
3 | 6 |
|
4 | 7 | 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 | + |
6 | 31 |
|
| 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()) |
7 | 80 |
|
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 |
12 | 92 |
|
13 | 93 |
|
14 | 94 | if __name__ == '__main__':
|
15 |
| - main() |
| 95 | + exit(main()) |
0 commit comments