1
+ import glob
2
+ import hashlib
1
3
import os
4
+ import platform
2
5
import sys
3
- import glob
4
6
import shutil
7
+ import tarfile
5
8
import textwrap
6
- import platform
9
+ import zipfile
7
10
8
11
from tempfile import mkstemp , gettempdir
9
- import zipfile
10
- import tarfile
12
+ from urllib .request import urlopen , Request
11
13
12
14
OPENBLAS_V = '0.3.9'
13
15
# Temporary build of OpenBLAS to test a fix for dynamic detection of CPU
14
16
OPENBLAS_LONG = 'v0.3.7-527-g79fd006c' # the 0.3.7 is misleading
15
17
BASE_LOC = 'https://anaconda.org/multibuild-wheels-staging/openblas-libs'
16
18
BASEURL = f'{ BASE_LOC } /{ OPENBLAS_LONG } /download'
17
19
ARCHITECTURES = ['' , 'windows' , 'darwin' , 'aarch64' , 'x86_64' , 'i686' , 'ppc64le' , 's390x' ]
20
+ sha256_vals = {
21
+ "openblas-v0.3.7-527-g79fd006c-win_amd64-gcc_7_1_0.zip" : "7249d68c02e6b6339e06edfeab1fecddf29ee1e67a3afaa77917c320c43de840" ,
22
+ "openblas64_-v0.3.7-527-g79fd006c-win_amd64-gcc_7_1_0.zip" : "6488e0961a5926e47242f63b63b41cfdd661e6f1d267e8e313e397cde4775c17" ,
23
+ "openblas-v0.3.7-527-g79fd006c-macosx_10_9_x86_64-gf_1becaaa.tar.gz" : "69434bd626bbc495da9ce8c36b005d140c75e3c47f94e88c764a199e820f9259" ,
24
+ "openblas64_-v0.3.7-527-g79fd006c-macosx_10_9_x86_64-gf_1becaaa.tar.gz" : "093f6d953e3fa76a86809be67bd1f0b27656671b5a55b233169cfaa43fd63e22" ,
25
+ "openblas-v0.3.7-527-g79fd006c-manylinux2014_aarch64.tar.gz" : "42676c69dc48cd6e412251b39da6b955a5a0e00323ddd77f9137f7c259d35319" ,
26
+ "openblas64_-v0.3.7-527-g79fd006c-manylinux2014_aarch64.tar.gz" : "5aec167af4052cf5e9e3e416c522d9794efabf03a2aea78b9bb3adc94f0b73d8" ,
27
+ "openblas-v0.3.7-527-g79fd006c-manylinux2010_x86_64.tar.gz" : "fa67c6cc29d4cc5c70a147c80526243239a6f95fc3feadcf83a78176cd9c526b" ,
28
+ "openblas64_-v0.3.7-527-g79fd006c-manylinux2010_x86_64.tar.gz" : "9ad34e89a5307dcf5823bf5c020580d0559a0c155fe85b44fc219752e61852b0" ,
29
+ "openblas-v0.3.7-527-g79fd006c-manylinux2010_i686.tar.gz" : "0b8595d316c8b7be84ab1f1d5a0c89c1b35f7c987cdaf61d441bcba7ab4c7439" ,
30
+ "openblas-v0.3.7-527-g79fd006c-manylinux2014_ppc64le.tar.gz" : "3e1c7d6472c34e7210e3605be4bac9ddd32f613d44297dc50cf2d067e720c4a9" ,
31
+ "openblas64_-v0.3.7-527-g79fd006c-manylinux2014_ppc64le.tar.gz" : "a0885873298e21297a04be6cb7355a585df4fa4873e436b4c16c0a18fc9073ea" ,
32
+ "openblas-v0.3.7-527-g79fd006c-manylinux2014_s390x.tar.gz" : "79b454320817574e20499d58f05259ed35213bea0158953992b910607b17f240" ,
33
+ "openblas64_-v0.3.7-527-g79fd006c-manylinux2014_s390x.tar.gz" : "9fddbebf5301518fc4a5d2022a61886544a0566868c8c014359a1ee6b17f2814" ,
34
+ }
35
+
18
36
19
37
IS_32BIT = sys .maxsize < 2 ** 32
38
+
20
39
def get_arch ():
21
40
if platform .system () == 'Windows' :
22
41
ret = 'windows'
@@ -50,10 +69,12 @@ def get_manylinux(arch):
50
69
51
70
52
71
def download_openblas (target , arch , ilp64 ):
53
- import urllib3
54
72
ml_ver = get_manylinux (arch )
55
73
fnsuffix = {None : "" , "64_" : "64_" }[ilp64 ]
56
74
filename = ''
75
+ headers = {'User-Agent' : ('Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 ; '
76
+ '(KHTML, like Gecko) Chrome/41.0.2228.0 '
77
+ 'Safari/537.3' )}
57
78
if arch in ('aarch64' , 'ppc64le' , 's390x' , 'x86_64' , 'i686' ):
58
79
suffix = f'manylinux{ ml_ver } _{ arch } .tar.gz'
59
80
filename = f'{ BASEURL } /openblas{ fnsuffix } -{ OPENBLAS_LONG } -{ suffix } '
@@ -71,15 +92,26 @@ def download_openblas(target, arch, ilp64):
71
92
typ = 'zip'
72
93
if not filename :
73
94
return None
74
- print ( "Downloading:" , filename , file = sys . stderr )
75
- http = urllib3 . PoolManager ( )
76
- response = http . request ( 'GET' , filename )
95
+ req = Request ( url = filename , headers = headers )
96
+ response = urlopen ( req )
97
+ length = response . getheader ( 'content-length' )
77
98
if response .status != 200 :
78
99
print (f'Could not download "{ filename } "' , file = sys .stderr )
79
100
return None
101
+ print (f"Downloading { length } from { filename } " , file = sys .stderr )
102
+ data = response .read ()
103
+ # Verify hash
104
+ key = os .path .basename (filename )
105
+ sha256_returned = hashlib .sha256 (data ).hexdigest ()
106
+ if key not in sha256_vals :
107
+ raise ValueError (
108
+ f'key "{ key } " with hash "{ sha256_returned } " not in sha256_vals' )
109
+ sha256_expected = sha256_vals [key ]
110
+ if sha256_returned != sha256_expected :
111
+ raise ValueError (f'sha256 hash mismatch for filename { filename } ' )
80
112
print ("Saving to file" , file = sys .stderr )
81
113
with open (target , 'wb' ) as fid :
82
- fid .write (response . data )
114
+ fid .write (data )
83
115
return typ
84
116
85
117
def setup_openblas (arch = get_arch (), ilp64 = get_ilp64 ()):
@@ -201,9 +233,10 @@ def test_setup(arches):
201
233
def items ():
202
234
for arch in arches :
203
235
yield arch , None
204
- if arch in ('x86' , 'darwin' , 'windows ' ):
236
+ if arch not in ('i686 ' ):
205
237
yield arch , '64_'
206
238
239
+ errs = []
207
240
for arch , ilp64 in items ():
208
241
if arch == '' :
209
242
continue
@@ -212,9 +245,11 @@ def items():
212
245
try :
213
246
try :
214
247
target = setup_openblas (arch , ilp64 )
215
- except :
216
- print (f'Could not setup { arch } ' )
217
- raise
248
+ except Exception as e :
249
+ print (f'Could not setup { arch } :' )
250
+ print (str (e ))
251
+ errs .append (e )
252
+ continue
218
253
if not target :
219
254
raise RuntimeError (f'Could not setup { arch } ' )
220
255
print (target )
@@ -231,6 +266,9 @@ def items():
231
266
os .unlink (target )
232
267
else :
233
268
shutil .rmtree (target )
269
+ if errs :
270
+ raise errs [0 ]
271
+
234
272
235
273
def test_version (expected_version , ilp64 = get_ilp64 ()):
236
274
"""
0 commit comments