|
| 1 | +# coding: utf-8 |
| 2 | +from __future__ import absolute_import, division, print_function |
| 3 | + |
| 4 | +import os |
| 5 | +import pip |
| 6 | +import struct |
| 7 | +import ssl |
| 8 | +import sys |
| 9 | + |
| 10 | +from six.moves.urllib.request import urlretrieve |
| 11 | + |
| 12 | + |
| 13 | +def download_wheel(name, version): |
| 14 | + base_url = os.getenv('WHEEL_URL') |
| 15 | + if base_url is None: |
| 16 | + raise ValueError('WHEEL_URL environment variable is missing.') |
| 17 | + |
| 18 | + py = 'cp{0[0]}{0[1]}'.format(sys.version_info) |
| 19 | + if py not in {'cp27', 'cp34', 'cp35'}: |
| 20 | + print('{} wheel not available for {}'.format(name, py)) |
| 21 | + return None |
| 22 | + |
| 23 | + bits = struct.calcsize('P') * 8 |
| 24 | + if bits == 32: |
| 25 | + arch = 'win32' |
| 26 | + elif bits == 64: |
| 27 | + arch = 'win_amd64' |
| 28 | + else: |
| 29 | + raise ValueError("Couldn't determine 32/64 bits.") |
| 30 | + |
| 31 | + filename = '{}-{}-{}-none-{}.whl'.format(name, version, py, arch) |
| 32 | + |
| 33 | + directory = 'astrodynamics-wheels' |
| 34 | + os.mkdir(directory) |
| 35 | + |
| 36 | + filepath = os.path.join(directory, filename) |
| 37 | + url = base_url + filename |
| 38 | + |
| 39 | + urlretrieve(url, filepath) |
| 40 | + return filepath |
| 41 | + |
| 42 | + |
| 43 | +def download_numpy_wheel(): |
| 44 | + base_url = os.getenv('WHEEL_URL') |
| 45 | + if base_url is None: |
| 46 | + raise ValueError('WHEEL_URL environment variable is missing.') |
| 47 | + |
| 48 | + version = '1.10.4+mkl' |
| 49 | + py = 'cp{0[0]}{0[1]}'.format(sys.version_info) |
| 50 | + if py not in {'cp27', 'cp34', 'cp35'}: |
| 51 | + print('NumPy wheel not available for {}'.format(py)) |
| 52 | + return None |
| 53 | + |
| 54 | + bits = struct.calcsize('P') * 8 |
| 55 | + if bits == 32: |
| 56 | + arch = 'win32' |
| 57 | + elif bits == 64: |
| 58 | + arch = 'win_amd64' |
| 59 | + else: |
| 60 | + raise ValueError("Couldn't determine 32/64 bits.") |
| 61 | + |
| 62 | + filename = 'numpy-{}-{}-none-{}.whl'.format(version, py, arch) |
| 63 | + |
| 64 | + directory = 'astrodynamics-numpy-wheels' |
| 65 | + os.mkdir(directory) |
| 66 | + |
| 67 | + filepath = os.path.join(directory, filename) |
| 68 | + url = base_url + filename |
| 69 | + |
| 70 | + # Disable SSL. Shouldn't do this ever. This is just a script. |
| 71 | + ssl._create_default_https_context = ssl._create_unverified_context |
| 72 | + urlretrieve(url, filepath) |
| 73 | + return filepath |
| 74 | + |
| 75 | + |
| 76 | +def download_scipy_wheel(): |
| 77 | + base_url = os.getenv('WHEEL_URL') |
| 78 | + if base_url is None: |
| 79 | + raise ValueError('WHEEL_URL environment variable is missing.') |
| 80 | + |
| 81 | + version = '0.17.0' |
| 82 | + py = 'cp{0[0]}{0[1]}'.format(sys.version_info) |
| 83 | + if py not in {'cp27', 'cp34', 'cp35'}: |
| 84 | + print('SciPy wheel not available for {}'.format(py)) |
| 85 | + return None |
| 86 | + |
| 87 | + bits = struct.calcsize('P') * 8 |
| 88 | + if bits == 32: |
| 89 | + arch = 'win32' |
| 90 | + elif bits == 64: |
| 91 | + arch = 'win_amd64' |
| 92 | + else: |
| 93 | + raise ValueError("Couldn't determine 32/64 bits.") |
| 94 | + |
| 95 | + filename = 'scipy-{}-{}-none-{}.whl'.format(version, py, arch) |
| 96 | + |
| 97 | + directory = 'astrodynamics-numpy-wheels' |
| 98 | + os.mkdir(directory) |
| 99 | + |
| 100 | + filepath = os.path.join(directory, filename) |
| 101 | + url = base_url + filename |
| 102 | + |
| 103 | + urlretrieve(url, filepath) |
| 104 | + return filepath |
| 105 | + |
| 106 | + |
| 107 | +def install_numpy(): |
| 108 | + filepath = download_wheel('numpy', '1.10.4+mkl') |
| 109 | + if filepath: |
| 110 | + pip.main(['install', filepath]) |
| 111 | + else: |
| 112 | + pip.main(['install', 'numpy']) |
| 113 | + |
| 114 | + |
| 115 | +def install_scipy(): |
| 116 | + filepath = download_wheel('scipy', '0.17.0') |
| 117 | + if filepath: |
| 118 | + pip.main(['install', filepath]) |
| 119 | + else: |
| 120 | + pip.main(['install', 'scipy']) |
| 121 | + |
| 122 | +if __name__ == '__main__': |
| 123 | + # Disable SSL. Shouldn't do this ever. This is just a script. |
| 124 | + ssl._create_default_https_context = ssl._create_unverified_context |
| 125 | + install_numpy() |
| 126 | + install_scipy() |
0 commit comments