Skip to content
This repository was archived by the owner on Aug 30, 2024. It is now read-only.

Commit 50eaabd

Browse files
authored
Merge pull request #50 from mattip/windll
BUILD: add _distributor_local.py to preload dll on windows
2 parents e68eef5 + 5c16d58 commit 50eaabd

File tree

3 files changed

+47
-0
lines changed

3 files changed

+47
-0
lines changed

.appveyor.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,10 @@ install:
119119
build_script:
120120
- cd numpy
121121
- git checkout %BUILD_COMMIT%
122+
# Create _distributor_init.py
123+
- cd ..
124+
- python -c "import openblas_support; openblas_support.make_init('numpy')"
125+
- cd numpy
122126
# Append license text relevant for the built wheel
123127
- type ..\LICENSE_win32.txt >> LICENSE.txt
124128
- ps: |

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
*.pyc
22
*~
3+
*.swp
34
tmp_for_test/
45
working/
56
downloads/

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(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_path):
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)