Skip to content

Commit c9422ff

Browse files
committed
ENH: backport scipy changes to openblas download script
1 parent e664535 commit c9422ff

6 files changed

+57
-22
lines changed

azure-pipelines.yml

-2
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ stages:
4040
/bin/bash -xc "cd numpy && \
4141
/opt/python/cp38-cp38/bin/python -mvenv venv &&\
4242
source venv/bin/activate && \
43-
python3 -m pip install urllib3 && \
4443
target=\$(python3 tools/openblas_support.py) && \
4544
cp -r \$target/lib/* /usr/lib && \
4645
cp \$target/include/* /usr/include && \
@@ -122,7 +121,6 @@ stages:
122121
# primarily on file size / name details
123122
- script: |
124123
set -xe
125-
python -m pip install urllib3
126124
target=$(python tools/openblas_support.py)
127125
ls -lR $target
128126
# manually link to appropriate system paths

azure-steps-windows.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ steps:
1414
# to $PYTHON_EXE's directory since that is on a different drive which
1515
# mingw does not like. Instead copy it to a directory and set OPENBLAS,
1616
# since OPENBLAS will be picked up by the openblas discovery
17-
python -m pip install urllib3
17+
python -m pip install
1818
$target = $(python tools/openblas_support.py)
1919
mkdir openblas
2020
echo Copying $target to openblas/openblas$env:OPENBLAS_SUFFIX.a

shippable.yml

-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ build:
2525
- sudo add-apt-repository ppa:ubuntu-toolchain-r/test
2626
- sudo apt-get update
2727
- sudo apt-get install gcc gfortran libgfortran5
28-
- python -mpip install urllib3
2928
- target=$(python tools/openblas_support.py)
3029
- ls -lR "${target}"
3130
- sudo cp -r "${target}"/lib/* /usr/lib

tools/openblas_support.py

+51-13
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,41 @@
1+
import glob
2+
import hashlib
13
import os
4+
import platform
25
import sys
3-
import glob
46
import shutil
7+
import tarfile
58
import textwrap
6-
import platform
9+
import zipfile
710

811
from tempfile import mkstemp, gettempdir
9-
import zipfile
10-
import tarfile
12+
from urllib.request import urlopen, Request
1113

1214
OPENBLAS_V = '0.3.9'
1315
# Temporary build of OpenBLAS to test a fix for dynamic detection of CPU
1416
OPENBLAS_LONG = 'v0.3.7-527-g79fd006c' # the 0.3.7 is misleading
1517
BASE_LOC = 'https://anaconda.org/multibuild-wheels-staging/openblas-libs'
1618
BASEURL = f'{BASE_LOC}/{OPENBLAS_LONG}/download'
1719
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+
1836

1937
IS_32BIT = sys.maxsize < 2**32
38+
2039
def get_arch():
2140
if platform.system() == 'Windows':
2241
ret = 'windows'
@@ -50,10 +69,12 @@ def get_manylinux(arch):
5069

5170

5271
def download_openblas(target, arch, ilp64):
53-
import urllib3
5472
ml_ver = get_manylinux(arch)
5573
fnsuffix = {None: "", "64_": "64_"}[ilp64]
5674
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')}
5778
if arch in ('aarch64', 'ppc64le', 's390x', 'x86_64', 'i686'):
5879
suffix = f'manylinux{ml_ver}_{arch}.tar.gz'
5980
filename = f'{BASEURL}/openblas{fnsuffix}-{OPENBLAS_LONG}-{suffix}'
@@ -71,15 +92,26 @@ def download_openblas(target, arch, ilp64):
7192
typ = 'zip'
7293
if not filename:
7394
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')
7798
if response.status != 200:
7899
print(f'Could not download "{filename}"', file=sys.stderr)
79100
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}')
80112
print("Saving to file", file=sys.stderr)
81113
with open(target, 'wb') as fid:
82-
fid.write(response.data)
114+
fid.write(data)
83115
return typ
84116

85117
def setup_openblas(arch=get_arch(), ilp64=get_ilp64()):
@@ -201,9 +233,10 @@ def test_setup(arches):
201233
def items():
202234
for arch in arches:
203235
yield arch, None
204-
if arch in ('x86', 'darwin', 'windows'):
236+
if arch not in ('i686'):
205237
yield arch, '64_'
206238

239+
errs = []
207240
for arch, ilp64 in items():
208241
if arch == '':
209242
continue
@@ -212,9 +245,11 @@ def items():
212245
try:
213246
try:
214247
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
218253
if not target:
219254
raise RuntimeError(f'Could not setup {arch}')
220255
print(target)
@@ -231,6 +266,9 @@ def items():
231266
os.unlink(target)
232267
else:
233268
shutil.rmtree(target)
269+
if errs:
270+
raise errs[0]
271+
234272

235273
def test_version(expected_version, ilp64=get_ilp64()):
236274
"""

tools/pypy-test.sh

+4-3
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ set -o pipefail
66
# Print expanded commands
77
set -x
88

9-
#sudo apt-get -yq update
10-
#sudo apt-get -yq install libatlas-base-dev liblapack-dev gfortran-5 python3-urllib3
11-
F77=gfortran-5 F90=gfortran-5 \
9+
sudo apt-get -yq update
10+
sudo apt-get -yq install gfortran-5
11+
export F77=gfortran-5
12+
export F90=gfortran-5
1213

1314
# Download the proper OpenBLAS x64 precompiled library
1415
target=$(python3 tools/openblas_support.py)

tools/travis-before-install.sh

+1-2
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,7 @@ pip install --upgrade pip
4141
# A specific version of cython is required, so we read the cython package
4242
# requirement using `grep cython test_requirements.txt` instead of simply
4343
# writing 'pip install setuptools wheel cython'.
44-
# urllib3 is needed for openblas_support
45-
pip install setuptools wheel urllib3 `grep cython test_requirements.txt`
44+
pip install setuptools wheel `grep cython test_requirements.txt`
4645

4746
if [ -n "$DOWNLOAD_OPENBLAS" ]; then
4847
pwd

0 commit comments

Comments
 (0)