8000 Merge pull request #13772 from mattip/windll · rkern/numpy@880651c · GitHub
[go: up one dir, main page]

Skip to content

Commit 880651c

Browse files
authored
Merge pull request numpy#13772 from mattip/windll
BUILD: use numpy-wheels/openblas_support.py to create _distributor_init.py
2 parents 34224c1 + 5e68725 commit 880651c

File tree

3 files changed

+47
-27
lines changed

3 files changed

+47
-27
lines changed

azure-pipelines.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,10 @@ jobs:
172172
architecture: $(PYTHON_ARCH)
173173
- script: python -m pip install --upgrade pip setuptools wheel
174174
displayName: 'Install tools'
175+
- script: python -m pip install cython nose pytz pytest
176+
displayName: 'Install dependencies; some are optional to avoid test skips'
177+
- script: if [%INSTALL_PICKLE5%]==[1] python -m pip install pickle5
178+
displayName: 'Install optional pickle5 backport (only for python3.6 and 3.7)'
175179
- powershell: |
176180
$wc = New-Object net.webclient
177181
$wc.Downloadfile("$(OPENBLAS)", "openblas.zip")
@@ -187,12 +191,8 @@ jobs:
187191
choco install -y mingw --forcex86 --force --version=5.3.0
188192
displayName: 'Install 32-bit mingw for 32-bit builds'
189193
condition: eq(variables['BITS'], 32)
190-
- script: python -m pip install cython nose pytz pytest
191-
displayName: 'Install dependencies; some are optional to avoid test skips'
192194
# NOTE: for Windows builds it seems much more tractable to use runtests.py
193195
# vs. manual setup.py and then runtests.py for testing only
194-
- script: if [%INSTALL_PICKLE5%]==[1] python -m pip install pickle5
195-
displayName: 'Install optional pickle5 backport (only for python3.6 and 3.7)'
196196
- powershell: |
197197
If ($(BITS) -eq 32) {
198198
$env:NPY_DISTUTILS_APPEND_FLAGS = 1
@@ -201,6 +201,7 @@ jobs:
201201
$env:PATH = "C:\\tools\\mingw32\\bin;" + $env:PATH
202202
refreshenv
203203
}
204+
python -c "from tools import openblas_support; openblas_support.make_init('numpy')"
204205
pip wheel -v -v -v --wheel-dir=dist .
205206
206207
ls dist -r | Foreach-Object {

numpy/core/__init__.py

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,29 +5,6 @@
55

66
import os
77

8-
# on Windows NumPy loads an important OpenBLAS-related DLL
9-
# and the code below aims to alleviate issues with DLL
10-
# path resolution portability with an absolute path DLL load
11-
if os.name == 'nt':
12-
from ctypes import WinDLL
13-
import glob
14-
# convention for storing / loading the DLL from
15-
# numpy/.libs/, if present
16-
libs_path = os.path.abspath(os.path.join(os.path.dirname(__file__),
17-
'..', '.libs'))
18-
DLL_filenames = []
19-
if os.path.isdir(libs_path):
20-
for filename in glob.glob(os.path.join(libs_path, '*openblas*dll')):
21-
# NOTE: would it change behavior to load ALL
22-
# DLLs at this path vs. the name restriction?
23-
WinDLL(os.path.abspath(filename))
24-
DLL_filenames.append(filename)
25-
if len(DLL_filenames) > 1:
26-
import warnings
27-
warnings.warn("loaded more than 1 DLL from .libs:\n%s" %
28-
"\n".join(DLL_filenames),
29-
stacklevel=1)
30-
318
# disables OpenBLAS affinity setting of the main thread that limits
329
# python threads or processes to one core
3310
env_added = []

tools/openblas_support.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import os
2+
import textwrap
3+
4+
def make_init(dirname):
5+
'''
6+
Create a _distributor_init.py file for OpenBlas
7+
'''
8+
with open(os.path.join(dirname, '_distributor_init.py'), 'wt') as fid:
9+
fid.write(textwrap.dedent("""
10+
'''
11+
Helper to preload windows dlls to prevent dll not found errors.
12+
Once a DLL is preloaded, its namespace is made available to any
13+
subsequent DLL. This file originated in the numpy-wheels repo,
14+
and is created as part of the scripts that build the wheel.
15+
'''
16+
import os
17+
from ctypes import WinDLL
18+
import glob
19+
if os.name == 'nt':
20+
# convention for storing / loading the DLL from
21+
# numpy/.libs/, if present
22+
try:
23+
basedir = os.path.dirname(__file__)
24+
except:
25+
pass
26+
else:
27+
libs_dir = os.path.abspath(os.path.join(basedir, '.libs'))
28+
DLL_filenames = []
29+
if os.path.isdir(libs_dir):
30+
for filename in glob.glob(os.path.join(libs_dir,
31+
'*openblas*dll')):
32+
# NOTE: would it change behavior to load ALL
33+
# DLLs at this path vs. the name restriction?
34+
WinDLL(os.path.abspath(filename))
35+
DLL_filenames.append(filename)
36+
if len(DLL_filenames) > 1:
37+
import warnings
38+
warnings.warn("loaded more than 1 DLL from .libs:\\n%s" %
39+
"\\n".join(DLL_filenames),
40+
stacklevel=1)
41+
"""))
42+

0 commit comments

Comments
 (0)
0